1

I am building a component managing a set of job offers. Jobs have attributes including "employer". (I am extending a component created with Component Creator.)

There is a front-end list view with filtering that allows users to restrict the listed jobs to a particular employer (among other filtering options). Selecting an employer filter causes the following GET request to be generated:

http://localhost/joomla/index.php/job-boerse/set-of-jobs?filter[employer]=Google&<some more stuff>

This works nicely. However, now I wish to create a menu item type with an option, the employer, so I can create menu items, such as, Google Jobs, Apple Jobs, etc.. Essentially, I wish the menu items to preset the filter with a particular value that can be specified during menu item definition.

Ok. So I added the following options to the menu item type definition (joomla/components/com_jobs/views/jobs/templ/default.xml):

<?xml version="1.0" encoding="utf-8"?>
<metadata>
    <layout title="COM_JOBS_TITLE_LIST_VIEW_JOBSFULL" option="View">
        <message>
                        <![CDATA[COM_JOBS_TITLE_LIST_VIEW_JOBSFULL_DESC]]>
        </message>
    </layout>
    <!-- Add fields to the request variables for the layout. -->
    <fields name="request">
        <fieldset name="request">
            <field name="employer"
              type="text" 
              hint="COM_JOBS_FILTER_EMPLOYER_HINT"
              label="COM_JOBS_JOBS_EMPLOYER"
              class="js-stools-search-string" />
        </fieldset>
    </fields>
</metadata>

This works except, the Menu Item Link the system constructs is this:

index.php?option=com_jobs&view=jobs&employer=Google

instead of

index.php?option=com_jobs&view=jobs&filter[employer]=Google

Ok. So I changed the employer field name in default.xml as follows:

<field name="filter[employer]" ...

However, now, the system is unable to construct the Link for the menu item. I was hoping it would make the following Link but it didn't:

index.php?option=com_jobs&view=jobs&filter[employer]=Google

Moreover, when I save the menu item, the value of the employer field disappears from the form.

I guess, what I am missing is an understanding of how Joomla builds the Links for menu items with options. Maybe I need to change the option name from "employer" to "filter[employer]" in some other place as well?

1
  • A well contructed question - context, effort, and nothing to edit. +1 I hope that you continue to write high value posts like this. Welcome to JSE. Commented Jun 9, 2019 at 21:49

4 Answers 4

0

It seems that Joomla doesn't like field names with brackets. My workaround was to replace the brackets with their hex codes like so:

<field name="filter%5Bemployer%5D" ...

However, this solution is not perfect. When you edit the menu item, the employer field is empty while the filter%5Bemployer%5D link option is still there.

0

Add filter field group inside the request field group:

<fields name="request">
    <fieldset name="request">
        <fields name="filter">
            <field
                name="employer"
                type="text"
                label="COM_JOBS_JOBS_EMPLOYER"
                class="js-stools-search-string"
                hint="COM_JOBS_FILTER_EMPLOYER_HINT"
            />
        </fields>
    </fieldset>
</fields>
5
  • This doesn't seem to work for me. See my explanation in my additional answer. (I could not put enough text into this comment.) Commented Jun 11, 2019 at 14:16
  • @MuesliFlyer You must be doing something wrong because the resulting field name should be jform[request][filter][employer].
    – Sharky
    Commented Jun 11, 2019 at 15:32
  • I tried your's and various different approaches in default.xml, to no avail. When the fields are wrapped in a "fields name=filter" tag and I save the menu item, joomla doesn't include the fields in the link it constructs. Have you tried your proposal? Does it work for you? Commented Jun 13, 2019 at 9:22
  • @MuesliFlyer Yes, I tried it. Your issue sounds like you are adding filter field group outside of request group. But it must be a child of request.
    – Sharky
    Commented Jun 13, 2019 at 15:26
  • Whooah after hours of debugging I seem to have found the problem. It works when the filter fields group is not the first item in the fieldset. This seems to be a Joomla bug. I will report it. As a workaround a hidden field can be inserted before the filter fields group. (See my new answer.) Commented Jun 15, 2019 at 16:58
0

Sharky's answer doesn't seem to work for me. I believe, I found the code where the Link is composed: joomla/administrator/components/com_menus/controllers/item.php in the save function at about Line 360++

There is special handling for "request" fields, but I don't see any special handling for a "filter" field group.

The problem is likely related to the fact that form field names use brackets and don't seem to support nested brackets. When I name my field "filter[employer]" then the following input element is created:

<input type="text" name="jform[request][filter[employer]]"
id="jform_request_filter_employer_" value=""
class="js-stools-search-string" placeholder=" - Search Employer - ">

When I save the menu item, the value for jform[request][filter[employer]] is properly submitted (as HTTP parameter). The problem must occur when the Joomla server parses the parameter. Haven't yet been able to figure out where that is done.

1
  • Please be aware that, while it is okay to post multiple answers, the beauty of Stack Exchange sites is in the fact that the page content is not a chronologically sorted thread of posts. (I'm not saying that you have done anything wrong, just a word of advice to a newcomer.) Please edit your posts if you wish to extend them instead of posting multiple answers. Commented Jun 13, 2019 at 10:10
0

There seems to be a Joomla bug: The filter field group must not be the first item in the request fieldset. As a workaround, I added a hidden field before the filter group like so:

<fields name="request">
    <fieldset name="request">

        <!-- Needed because of Joomla bug: filter fields group cannot be first in the fieldset -->
        <field name="xxx" type="hidden" />

        <fields name="filter">
            <field name="employer"
              type="text" 
              hint="COM_JOBS_FILTER_EMPLOYER_HINT"
              label="COM_JOBS_JOBS_EMPLOYER"
              class="js-stools-search-string" />
        </fields>
    </fieldset>
</fields>

I will report this as a bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.