Tags
Tags copied to clipboard
Add string version of tag entity
I like this approach, let me know what you guys think.
This lets you do:
$muffin = $this->Muffins->get(1, ['contain' => ['Tags']]);
echo implode(', ', $muffin->tags);
So in a form, this should do:
$this->Form->input('tags', ['value' => implode(', ', $muffin->tags)]);
It isn't the prettiest yet but at this point we can either add TagAwareTrait::_getTags() which would automatically return the implode()d result or let it up to the users to use that in case they want strings or leave as is for multi-select.
To add the ID for their implementation, either do that when instantiating the table the first time:
$muffins = TableRegistry::get('Muffins');
$muffins->Tags->toStringTemplate(':id::label');
Or extend the TagsTable and define a custom $_toStringTemplate.
I think a helper would be the best way to handle the output of the tags. I don't like using the Table object everywhere. A helper would allow us to encapsulate all presentation logic properly an offer more than just a comma separated string. Here are a few examples:
echo $this->Tag->cloud($muffin->tags);
echo $this->Tag->string($muffin->tags, ['separator' => ',']);
echo $this->Tag->input($muffin->tags);
echo $this->Tag->select($muffin->tags);
The helper could use a template string just like the HTML helper for the cloud and tag string as well.
A helper on top of that is totally fine and actually the right way to go I believe.
What do you think about this? https://gist.github.com/burzum/4031a5b39071714af002
@ADmad Jad just told me to do this on Skype:
Not yet currently driving cant comment but i will need this plugin soon. Bump it so admad sees it too please.
:smile:
bump
@ADmad your feedback please? See the 2nd last comment up from this one.
This patch seems fine but it lacks tests :( I don't have the time to add them and @jadb seem to have been abducted by aliens.
@burzum Your helper prototype seems fine too. If you want to make a proper PR for it i'll merge it.
Am here, am here... just haven't been having the greatest of times, though things are starting to be much better.
I don't have time to add tests myself ATM, so anyone's help would be very much appreciated :smile:
@ADmad no time for it right now. I'm renovating three rooms and have a ton of work after my vacation.
I can write tests tomorrow.
Maybe the aliens just gave him back a day so it appeared they didnt take him, though they now might have after all for good.
I implemented this in the new tags repo @ https://github.com/dereuromark/cakephp-tags Using a basic tag_list property to store and retreive as string. Works for forms, easy enough for most use cases. Rest indeed can be implemented on helper level.