? Failure

User tests: Successful: Unsuccessful:

avatar justinherrin
justinherrin
22 Jul 2017

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.

Summary of Changes

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)))

Testing Instructions

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 :)

Documentation Changes Required

I would imagine that some documentation somewhere would need updating. I'd be happy to contribute as needed if folks would like.

avatar joomla-cms-bot joomla-cms-bot - change - 22 Jul 2017
Category Libraries
avatar justinherrin justinherrin - open - 22 Jul 2017
avatar justinherrin justinherrin - change - 22 Jul 2017
Status New Pending
avatar franz-wohlkoenig franz-wohlkoenig - change - 1 Nov 2017
Status Pending Needs Review
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 1 Nov 2017

Status is set on "Needs Review".

avatar mbabker
mbabker - comment - 21 Jul 2018

Aside from needing merge conflicts resolved since it's so old, is there really absolutely zero interest in this thing?

avatar franz-wohlkoenig franz-wohlkoenig - change - 21 Jul 2018
Status Needs Review Information Required
avatar ggppdk
ggppdk - comment - 21 Jul 2018

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

avatar justinherrin
justinherrin - comment - 21 Jul 2018

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.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 17 Aug 2018

i have Interest on this PR and would test it.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/17211.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 17 Aug 2018

i have Interest on this PR and would test it.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/17211.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 24 Aug 2018

@justinherrin any Update on test or not?

avatar justinherrin
justinherrin - comment - 24 Aug 2018

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.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 24 Aug 2018

@justinherrin thanks for Info and Work. Looking forward if PR coming for Test.

avatar franz-wohlkoenig franz-wohlkoenig - change - 19 Mar 2019
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2019-03-19 06:54:24
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - change - 19 Mar 2019
Closed_Date 2019-03-19 06:54:24 2019-03-19 06:54:25
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 19 Mar 2019
avatar joomla-cms-bot
joomla-cms-bot - comment - 19 Mar 2019
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 19 Mar 2019

closed as no Response.

Add a Comment

Login with GitHub to post a comment