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

Widget for tag display #6

Open
antonkomarev opened this issue Jan 19, 2015 · 11 comments
Open

Widget for tag display #6

antonkomarev opened this issue Jan 19, 2015 · 11 comments
Assignees

Comments

@antonkomarev
Copy link
Contributor

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
Copy link
Owner

We need to think around that widget features.

@creocoder creocoder self-assigned this Jan 19, 2015
@antonkomarev
Copy link
Contributor Author

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
Copy link
Owner

@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
Copy link
Owner

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

@antonkomarev
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Owner

@a-komarev It already handled by framework.

@antonkomarev
Copy link
Contributor Author

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
Copy link
Owner

@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
Copy link
Contributor Author

@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
Copy link
Owner

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

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

No branches or pull requests

2 participants