I am building a component managing a set of job offers. Jobs have attributes including "employer".
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?option=com_jobs&view=jobs&filter[employer]=Google
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 a filter field group 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_JOBS_TEST" option="View">
<message>
<![CDATA[COM_JOBS_TITLE_LIST_VIEW_JOBS_DESC]]>
</message>
</layout>
<!-- Add fields to the request variables for the layout. -->
<fields name="request">
<fieldset name="request">
<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>
</metadata>
When I create a menu item of this type and I enter Google into the employer field and save the menu item, the following link should be created for it:
index.php?option=com_jobs&view=jobs&filter[employer]=Google
index.php?option=com_jobs&view=jobs
Moreover, after saving, the employer field becomes empty.
PHP erstellt für Linux Compluter5 4.15.0-51-generic #55-Ubuntu SMP Wed May 15 14:27:21 UTC 2019 x86_64
Datenbanktyp mysql
Datenbankversion 5.5.5-10.3.13-MariaDB-1:10.3.13+maria~xenial
Datenbankzeichensatz utf8_general_ci
Datenbankverbindungszeichensatz utf8mb4_general_ci
PHP-Version 7.2.19-0ubuntu0.18.04.1
Webserver Apache/2.4.29 (Ubuntu)
PHP-Interface für den Webserver apache2handler
Joomla!-Version Joomla! 3.9.5 Stable [ Amani ] 9-April-2019 15:00 GMT
Joomla!-Plattform-Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
Browsererkennung Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0
The problem occurs only if the filter field group is the first element (or only element?) in the request fieldset. A workaround is to insert a hidden field like so:
<fields name="request">
<fieldset name="request">
<!-- Needed because of Joomla bug: 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>
A possible fix is to set the $nested parameter of getGroup to true in administrator/components/com_menus/controllers/item.php at about line 360:
// Preprocess request fields to ensure that we remove not set or empty request params
- $request = $form->getGroup('request');
+ $request = $form->getGroup('request', true);
With this change, $request will no longer be empty. This solves the problem but I am not sure what other unintended effects the change might have.
Labels |
Added:
J3 Issue
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-06-15 18:45:52 |
Closed_By | ⇒ | franz-wohlkoenig |
Indeed, I was not on the latest version. I thought I would be notified automatically, but I wasn't. Ok. Now I am on 3.9.8. I tested the issue with the new version and the problem persists.
@muesliflyer as @SharkyKZ wrote above please test the Pull Request #25213
Please update to latest Version 3.9.8