It seem's that after upgrading to the latest mage 2 build, the category admin layout has changed slightly (unless i'm missing something) and I'm unable to see my custom category attributes....
2 Answers
The add/edit form for categories is not generated anymore by a block that retrieves all the attributes and generates a field depending on the type of the attribute.
The form is defined using ui-components.
This is the file that generates the form: https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/view/adminhtml/ui_component/category_form.xml
To include your custom attribute you have to add a similar file in your module.
Here is an example.
[Namespace]\[Moduule]\view\adminhtml\ui_component\category_form.xml
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
<field name="some_custom_field">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">50</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">input</item>
<item name="label" xsi:type="string" translate="true">Some custom field</item>
</item>
</argument>
</field>
</fieldset>
</form>
the file above will add a new input field in your category form.
-
Thanks for that. I use an external datasource - just wondered if you knew how that was referenced off the top of your head. If not no worries I'll dig. Thanks– encodesCommented May 27, 2016 at 8:39
-
Hello @marius, can you guide how to add 'note' on category attributes? I have tried few things like
note
andcomment
but not able to add note on my custom category attribute. Commented Oct 18, 2018 at 10:45 -
I am trying to add my attributes using this but the image input is not working... it wont save the image and it will return "Backend model is not specified for landing_page_image" or "The image was not upload" before it was so easy, any idea ? here is my category_form.xml code
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
<field name="is_landing_page">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">61</item>
<item name="dataType" xsi:type="string">boolean</item>
<item name="formElement" xsi:type="string">checkbox</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="label" xsi:type="string" translate="true">Is landing page?</item>
<item name="valueMap" xsi:type="array">
<item name="true" xsi:type="string">1</item>
<item name="false" xsi:type="string">0</item>
</item>
<item name="default" xsi:type="string">0</item>
</item>
</argument>
</field>
<field name="landing_description">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Landing Description</item>
<item name="class" xsi:type="string">Magento\Catalog\Ui\Component\Category\Form\Element\Wysiwyg</item>
<item name="formElement" xsi:type="string">wysiwyg</item>
<item name="wysiwygConfigData" xsi:type="array">
<item name="settings" xsi:type="array">
<item name="theme_advanced_buttons1" xsi:type="string">bold,italic,|,justifyleft,justifycenter,justifyright,|,fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code</item>
<item name="theme_advanced_buttons2" xsi:type="boolean">false</item>
<item name="theme_advanced_buttons3" xsi:type="boolean">false</item>
<item name="theme_advanced_buttons4" xsi:type="boolean">false</item>
<item name="theme_advanced_statusbar_location" xsi:type="boolean">false</item>
</item>
<item name="files_browser_window_url" xsi:type="boolean">false</item>
<item name="height" xsi:type="string">100px</item>
<item name="toggle_button" xsi:type="boolean">false</item>
<item name="add_variables" xsi:type="boolean">false</item>
<item name="add_widgets" xsi:type="boolean">false</item>
<item name="add_images" xsi:type="boolean">false</item>
</item>
<item name="template" xsi:type="string">ui/form/field</item>
<item name="source" xsi:type="string">category</item>
<item name="wysiwyg" xsi:type="boolean">true</item>
<item name="dataScope" xsi:type="string">landing_description</item>
<item name="sortOrder" xsi:type="number">63</item>
<item name="rows" xsi:type="number">8</item>
</item>
</argument>
</field>
<field name="landing_page_image">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string">Landing Page Image</item>
<item name="dataType" xsi:type="string">string</item>
<item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
<item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
<item name="formElement" xsi:type="string">fileUploader</item>
<item name="source" xsi:type="string">category</item>
<item name="backend_model" xsi:type="string">Magento\Catalog\Model\Category\Attribute\Backend\Image</item>
<backend_model>Magento\Catalog\Model\Category\Attribute\Backend\Image</backend_model>
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="string">theme/design_config_fileUploader/save</item>
</item>
</item>
</argument>
</field>
</fieldset>
The custom description and checkbox are working fine, but "landing_page_image" wont work i lost a day trying to figure this out and i have nothing.
-
For anyone else trying to get around this, might be of interest github.com/magento/magento2/pull/5978– ChedarooCommented Apr 3, 2017 at 9:50