Magento2: Adding a new fieldset to the admin category editor changes the position of the 'General' fieldset.

Created on 7 May 2018  路  3Comments  路  Source: magento/magento2

Hi,

When a custom fieldset is added to the admin category editor, the General section (the one with "Enable category", "Include in Menu" and "Category Name") moves to the last position of the form.

It seems that this issue was already reported by somebody else in #5300, but it was closed. The problem remains, so I decided to open a new one.

Preconditions

I'm using Magento 2.2.3, PHP 7.1.16 and MySQL 5.7.22 with a default installation.

Steps to reproduce

Create a new module with the basic files (composer.json, etc/module.xml, registration.php, as specified in the developer documentation), and add the view/adminhtml/ui_component/category_form.xml file, with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
  <fieldset name="custom_fieldset">
    <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
        <item name="label" xsi:type="string" translate="true">Custom Fieldset</item>
        <item name="collapsible" xsi:type="boolean">true</item>
        <item name="sortOrder" xsi:type="number">200</item>
      </item>
    </argument>
  </fieldset>
</form>

There's no need to add a new category attribute. With just the new fieldset the problem appears.

Expected result

The general section, and its fields, should be at the top of the form so the category name is clearly visible:

expected result

Actual result

The general section is placed at the bottom of the form:

actual result

Workaround and possible solution

This seems to be related to the fact that the general fieldset doesn't have a configured sortOrder. In vendor/magento/module-catalog/view/adminhtml/ui_component/category_form.xml, you can see:

<fieldset name="general">
  <settings>
    <collapsible>false</collapsible>
    <label/>
  </settings>
  ...
</fieldset>

When adding a custom fieldset, somehow the fieldset gets merged in a different position of the resulting XML, giving a different display order. This can be confusing for site administrators (since the category name can be hidden below the fold if the website uses several extensions), and it's also confusing for developers.

A simple workaround is to add the sortOrder in our custom module's category_form.xml:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
  <fieldset name="custom_fieldset">
    <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
        <item name="label" xsi:type="string" translate="true">Custom Fieldset</item>
        <item name="collapsible" xsi:type="boolean">true</item>
        <item name="sortOrder" xsi:type="number">200</item>
      </item>
    </argument>
  </fieldset>

  <fieldset name="general" sortOrder="1">
  </fieldset>
</form>

A proper fix would be to add the sortOrder to the definition in the Magento_Catalog module itself. In its category_form.xml file:

<fieldset name="general" sortOrder="5">
  <settings>
    <collapsible>false</collapsible>
    <label/>
    <sortOrder>
  </settings>
  ...
</fieldset>
Catalog Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.2.x Reproduced on 2.3.x good first issue

All 3 comments

Hello @leoquijano, thank you for your report.
We've acknowledged the issue and added to our backlog.

Hi @leoquijano. Thank you for your report.
The issue has been fixed in magento/magento2#17540 by @vasilii-b in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.7 release.

Hi @leoquijano. Thank you for your report.
The issue has been fixed in magento/magento2#17604 by @jignesh-baldha in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

Was this page helpful?
0 / 5 - 0 ratings