creocoder / yii2-taggable

The taggable behavior for the Yii framework.
Other
134 stars 33 forks source link

Widget for tag display #6

Open antonkomarev opened 9 years ago

antonkomarev commented 9 years ago

Have you planned to create a widget to display tags with links on them in view actions or this repository will contain only TaggableBehavior? IMHO: Separate repository with require will be better solution.

creocoder commented 9 years ago

We need to think around that widget features.

antonkomarev commented 9 years ago

All cases i could imagine for tags widgets but not sure all of them will be really useful:

  1. Display tags of model as list with <li> elements (main goal of widget).
  2. Add configurable links for model's tags like: /post/tag/awesome-tag -> will display all posts tagged as awesome-tag
  3. Add configurable links for global tags list: /tag/awesome-tag -> will display all model types tagged as awesome-tag (posts, articles & news for example).
  4. Ability to select more than one tag to filter models.
  5. Show related tags (usually using together in models).
  6. Ajax adding tags (without going to model editing page) if allowed in RBAC.
  7. Ajax removing tags (without going to model editing page) if allowed in RBAC.
  8. Not sure about it (semantically better use lists for it), but another tag wrappers could be useful, like each tag in <span>.
  9. Tags cloud
  10. Drag & drop tags to change their ordering.

It's more than one widget described here. Let the discussion be started! :}

creocoder commented 9 years ago

@a-komarev

I think 1+2+3+4+5+8 = one widget. And 9 = other widget.

Separate repository with require will be better solution.

I do not think its good idea since taggable name choosed not only for behavior, but for highly reusable components around tagging staff.

creocoder commented 9 years ago

@a-komarev As i see we have 2 widgets here (except 6,7,10): TagWidget and TagCloudWidget. Both use Menu for rendering.

antonkomarev commented 9 years ago

6, 7, 10 are for TagInputWidget. But they should be implemented as button to quick edit in TagWidget. When you click on it - TagWidget replacing by TagInputWidget. Which will be replaced by TagWidget when you are pressing buttons Save or Cancel.

antonkomarev commented 9 years ago

Display widgets should be able to replace spaces in links with + sign. It's W3C standard:

URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

Example: Tag url good practice should be linked to /tag/url+good+practice

creocoder commented 9 years ago

@a-komarev It already handled by framework.

antonkomarev commented 9 years ago

Am I missed something?

<?php foreach ($model->tagNames as $tag) : ?>
    <?= Html::a($tag, ['/tag/' . $tag]) ?>
<?php endforeach ?>

This code generating me links with spaces: /tag/url good practice.

creocoder commented 9 years ago

@a-komarev

Am I missed something?

Yes, ofcource. This:

<?= Html::a($tag, ['/tag/' . $tag]) ?>

is not right solution. Such tasks should be solved by configuring urlManager rules + using code like this:

<?= Html::a($tag, ['/tag/index', 'tag' => $tag]) ?>

or even better:

<?= Html::a($tag, ['/tag/index', 'tagSlug' => $tagSlug]) ?>

Last example when Tag model use SluggableBehavior.

Rules example:

'rules' => [
    'tag/<tag>' => 'tag/index',
    // or
    'tag/<tagSlug>' => 'tag/index',
],
antonkomarev commented 9 years ago

@creocoder Thanks for a brief explanation! And this way more flexible for multiple tags filtering I suppose.

I reserved tag/index method for list of all tags and tag/view is working well now. Tags are passing through params with + sign instead of spaces.

<?php foreach ($model->getTagNames(true) as $tag) : ?>
    <?= Html::a($tag, ['/tag/view', 'tag' => $tag]) ?>
<?php endforeach ?>

Haven't thought about SluggableBehavior for tags, but sounds interesting. Will be great to have an example of this way in wiki of this repository.

creocoder commented 9 years ago

@a-komarev Can you open separate documentation issue? We can explain how to set up urlManager + show controller and other examples inside Advanced Usage section.