Skip to content

Menu item type: filter field group doesn't work when first in request fieldset #25211

@muesliflyer

Description

@muesliflyer

Steps to reproduce the issue

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>

Expected result

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

Actual result

index.php?option=com_jobs&view=jobs

Moreover, after saving, the employer field becomes empty.

System information (as much as possible)

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 

Additional comments

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions