User tests: Successful: Unsuccessful:
Hello all. When developing my own components and using the core Categories system, I have come across a need to have the ability to filter the default Categories dropdown list by a Parent Category. So I figured I'd share this PR in hopes it can be incorporated into the project.
Only one file was changed (libraries/cms/html/category.php
). Updated the query statement to allow for filter.parent
which would filter the categories based off of a specific Parent Category ID number (or an array of parent ID numbers).
With this change a developer can now use some code like the following to filter the default Categories dropdown list...
Filter by a single Parent ID number:
JHtml::_('category.options', 'com_customcomponentname', $config = array('filter.published' => array(1), 'filter.parent_id' => 15))
Filter by multiple Parent ID numbers:
JHtml::_('category.options', 'com_customcomponentname', $config = array('filter.published' => array(1), 'filter.parent_id' => array(15,37)))
This can be easily tested using a custom component, specifically when doing a front-end view. Here is an example Categories setup for the custom component:
Books
– Books Subcategory 1
– Books Subcategory 2
Movies
– Movies Subcategory 1
– Movies Subcategory 2
Toys
– Toys Subcategory 1
– Toys Subcategory 2
Now previously if you used JHtml::_('category.options')
to do the dropdown list of Categories, all of the Categories for the Custom Component would be listed. So the big list above would be shown. But what if you had a front-end view for Movies? The Books and Toys categories would be shown too. A bit odd and confusing for end users.
With this PR in place, you can now add filter.parent_id
to the $config
array, like the following code, to show only the Movies categories when on the Movies front-end view...
<select id="filter_category" name="filter_category" class="input-block-level" onchange="this.form.submit()">
<option value=""><?php echo JText::_('- Show All Movies -'); ?></option>
<?php echo JHtml::_('select.options', JHtml::_('category.options', 'com_customcomponentname', $config = array('filter.published' => array(1), 'filter.parent_id' => 15)), 'value', 'text', $this->state->get('filter.category')); ?>
</select>
Just change parent_id 15
to whatever ID number it is in your setup and your Categories dropdown will now only show...
– Movies Subcategory 1
– Movies Subcategory 2
No more un-relevant categories listed on specific views and no more confusion for the users :)
I would imagine that some documentation somewhere would need updating. I'd be happy to contribute as needed if folks would like.
Category | ⇒ | Libraries |
Status | New | ⇒ | Pending |
Status | Pending | ⇒ | Needs Review |
Aside from needing merge conflicts resolved since it's so old, is there really absolutely zero interest in this thing?
Status | Needs Review | ⇒ | Information Required |
This could be nice,
just it should be noted (code review, please correct me here), that it limits to the immediate descendants (children) of parent id(s) given
it does not include the full sub-trees as one would expect
I had hoped there was interest in this PR when I posted it originally. But wow, a whole year has gone by since that time. I'm obviously still interested and think it would be cool to have included, but if no one else cares, then it is what it is, and we can move on.
Let me know if I should spend some time fixing the "it's so old it has merge conflicts" issue.
i have Interest on this PR and would test it.
i have Interest on this PR and would test it.
@justinherrin any Update on test or not?
Hello. I honestly have not had any time this past week to do anything other than work
Hopefully this weekend I can get another PR submitted for people to test.
@justinherrin thanks for Info and Work. Looking forward if PR coming for Test.
Status | Information Required | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-03-19 06:54:24 |
Closed_By | ⇒ | franz-wohlkoenig |
Closed_Date | 2019-03-19 06:54:24 | ⇒ | 2019-03-19 06:54:25 |
Closed_By | franz-wohlkoenig | ⇒ | joomla-cms-bot |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/17211
closed as no Response.
Status is set on "Needs Review".