Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string version of tag entity #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add string version of tag entity #9

wants to merge 1 commit into from

Conversation

jadb
Copy link
Member

@jadb jadb commented Apr 24, 2015

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.

@burzum
Copy link
Contributor

burzum commented Apr 26, 2015

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.

@jadb
Copy link
Member Author

jadb commented Apr 26, 2015

A helper on top of that is totally fine and actually the right way to go I believe.

@burzum
Copy link
Contributor

burzum commented Apr 26, 2015

What do you think about this? https://gist.github.com/burzum/4031a5b39071714af002

@burzum
Copy link
Contributor

burzum commented Jun 18, 2015

@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.

😄

@josegonzalez
Copy link
Contributor

bump

@burzum
Copy link
Contributor

burzum commented Jan 3, 2016

@ADmad your feedback please? See the 2nd last comment up from this one.

@ADmad
Copy link
Member

ADmad commented Jan 5, 2016

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.

@jadb
Copy link
Member Author

jadb commented Jan 5, 2016

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 😄

@burzum
Copy link
Contributor

burzum commented Jan 5, 2016

@ADmad no time for it right now. I'm renovating three rooms and have a ton of work after my vacation.

@josegonzalez
Copy link
Contributor

I can write tests tomorrow.

@dereuromark
Copy link

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.

@dereuromark
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants