{"id":12639,"date":"2017-03-16T13:31:02","date_gmt":"2017-03-16T10:31:02","guid":{"rendered":"http:\/\/blog.belvg.com\/?p=12639"},"modified":"2019-09-18T17:45:57","modified_gmt":"2019-09-18T15:45:57","slug":"a-category-chooser-in-magento-2-backend","status":"publish","type":"post","link":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html","title":{"rendered":"A \u201cCategory Chooser\u201d in Magento 2 Backend"},"content":{"rendered":"\n<p>Let&rsquo;s imagine, you need to create a category chooser for magento admin panel. For example, this might be necessary in the following cases:<!--more--><\/p>\n<p>1. To be used for some standard form as follows:<\/p>\n<pre class=\"lang:php decode:true \">$fieldset-&gt;addField(\r\n\t'category_chooser',\r\n\t'[Vendor]\\[Modul]\\Block\\Adminhtml\\[Chooser]',\r\n\t[\r\n    \t'name' =&gt; 'category_chooser',\r\n    \t'label' =&gt; __('Categories'),\r\n    \t'title' =&gt; __('Categories'),\r\n    \t'required' =&gt; true\r\n\t]\r\n);\r\n<\/pre>\n<p>2. For some backend configurations:<\/p>\n<pre class=\"lang:php decode:true \">&lt;field id=\"category_chooser\" translate=\"label\" sortOrder=\"20\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\"&gt;\r\n    &lt;label&gt;Categories&lt;\/label&gt;\r\n    &lt;frontend_model&gt;[Vendor]\\[Modul]\\Block\\Adminhtml\\[Chooser]&lt;\/frontend_model&gt;\r\n&lt;\/field&gt;\r\n<\/pre>\n<p>3. Or, like in my case, for some widgets:<\/p>\n<pre class=\"lang:php decode:true \">&lt;parameter name=\"category_chooser\" xsi:type=\"block\" visible=\"true\" required=\"true\" sort_order=\"10\"&gt;\r\n\t&lt;label translate=\"true\"&gt;Categories&lt;\/label&gt;\r\n\t&lt;block class=\"[Vendor]\\[Modul]\\Block\\Adminhtml\\[Chooser]\" \/&gt;\r\n&lt;\/parameter&gt;\r\n<\/pre>\n<p>So, let&rsquo;s consider how it is possible to arrange that. Magento source code offers us several solutions but we have selected the simplest one to use. First off, we write down the code for the element itself:<\/p>\n<pre class=\"lang:php decode:true \">\tprotected function _elementHtml()\r\n\t{\r\n    \t$element = $this-&gt;_element;\r\n    \t$htmlId  = $element-&gt;getId();\r\n        $data\t= $element-&gt;getData();\r\n \r\n        $data['after_element_js']   = $this-&gt;_afterElementJs();\r\n        $data['after_element_html'] = $this-&gt;_afterElementHtml();\r\n        $data['readonly']       \t= 'readonly';\r\n \r\n        $objectManager  = \\Magento\\Framework\\App\\ObjectManager::getInstance();\r\n        $elementFactory = $objectManager-&gt;get('\\Magento\\Framework\\Data\\Form\\Element\\Factory');\r\n \r\n    \t$htmlItem = $elementFactory-&gt;create('text', ['data' =&gt; $data]);\r\n  \t  $htmlItem\r\n            -&gt;setId(\"{$htmlId}\")\r\n            -&gt;setForm($element-&gt;getForm())\r\n            -&gt;addClass('required-entry')\r\n            -&gt;addClass('entities');\r\n \r\n        $return  = &lt;&lt;&lt;HTML\r\n            &lt;div id=\"{$htmlId}-container\" class=\"chooser_container\"&gt;\r\n                {$htmlItem-&gt;getElementHtml()}\r\n            &lt;\/div&gt;\r\nHTML;\r\n \r\n    \treturn $return;\r\n\t}\r\n<\/pre>\n<div class=\"module_in_content_container\"><a href=\"https:\/\/belvg.com\/magento-custom-development\" class=\"link_to_module\" target=\"_blank\" rel=\"noopener\"><\/a><div class=\"module_content\"><img src=\"\" width=\"\" height=\"\" alt=\"\" class=\"module_image\" title=\"A &ldquo;Category Chooser&rdquo; in Magento 2 Backend\"><div class=\"module_content_part\"><h3 class=\"title\">Magento Custom Development<\/h3><p class=\"module_content_text\">Take your online store to the next level with BelVG Magento custom development<\/p><a href=\"https:\/\/belvg.com\/magento-custom-development\" class=\"link_2_to_module\" target=\"_blank\" style=\"display:inline-block\" rel=\"noopener\"><span class=\"read-more\">Visit the page<\/span><\/a><\/div><\/div><\/div>\n<p>But that is only a form&rsquo;s input. Now, let&rsquo;s write down some html and javascript code to output the chooser in the backend and let it perform properly:<\/p>\n<pre class=\"lang:php decode:true \">\tprotected function _afterElementHtml()\r\n\t{\r\n    \t$element = $this-&gt;_element;\r\n        $htmlId  = $element-&gt;getId();\r\n \r\n        $return  = &lt;&lt;&lt;HTML\r\n        \t&lt;a href=\"javascript:void(0)\" onclick=\"MultiCategoryChooser.displayChooser('{$htmlId}-container')\" class=\"widget-option-chooser\" title=\"{__('Open Chooser')}\"&gt;\r\n                &lt;img src=\"{$this-&gt;getViewFileUrl('images\/rule_chooser_trigger.gif')}\" alt=\"{__('Open Chooser')}\" \/&gt;\r\n            &lt;\/a&gt;\r\n        \t&lt;a href=\"javascript:void(0)\" onclick=\"MultiCategoryChooser.hideChooser('{$htmlId}-container')\" title=\"{__('Apply')}\"&gt;\r\n                &lt;img src=\"{$this-&gt;getViewFileUrl('images\/rule_component_apply.gif')}\" alt=\"{__('Apply')}\"&gt;\r\n            &lt;\/a&gt;\r\n \r\n            &lt;div class=\"chooser\"&gt;&lt;\/div&gt;\r\nHTML;\r\n \r\n    \treturn $return;\r\n\t}\r\n \r\n\tprotected function _afterElementJs()\r\n\t{\r\n        $chooserUrl = $this-&gt;getUrl('adminhtml\/widget_instance\/categories', []);\r\n        $element\t= $this-&gt;_element;\r\n        $htmlId \t= $element-&gt;getId();\r\n \r\n    \t$return = &lt;&lt;&lt;HTML\r\n            &lt;script&gt;\r\n\t            require([\r\n                    'jquery',\r\n                    'Magento_Ui\/js\/modal\/alert',\r\n                    \"prototype\"\r\n                ], function (jQuery, alert) {\r\n                    var MultiCategoryChooser = {\r\n                        displayChooser : function(chooser) {\r\n                        \tchooser  = $(chooser).down('div.chooser');\r\n                        \tentities = chooser.up('div.chooser_container').down('input[type=\"text\"].entities').value;\r\n                        \tpostParameters = {selected: entities};\r\n                        \turl = '{$chooserUrl}';\r\n \r\n                        \tif (chooser &amp;&amp; url) {\r\n                            \tif (chooser.innerHTML == '') {\r\n                                \tnew Ajax.Request(url, {\r\n                                        method \t: 'post',\r\n                                        parameters : postParameters,\r\n                                        onSuccess  : function(transport) {\r\n                                        \ttry {\r\n                                                if (transport.responseText) {\r\n                                                    Element.insert(chooser, transport.responseText);\r\n                                                    chooser.removeClassName('no-display');\r\n                                                    chooser.show();\r\n                                                }\r\n                                        \t} catch (e) {\r\n                                                alert({\r\n     \t                                           content: 'Error occurs during loading chooser.'\r\n                                                });\r\n                                        \t}\r\n                                    \t}\r\n                                    });\r\n                            \t} else {\r\n                                    chooser.removeClassName('no-display');\r\n                                    chooser.show();\r\n                            \t}\r\n                        \t}\r\n     \t               },\r\n                        hideChooser : function(chooser) {\r\n                        \tchooser = $(chooser).down('div.chooser');\r\n                        \tif (chooser) {\r\n                                chooser.addClassName('no-display');\r\n                            \tchooser.hide();\r\n                        \t}\r\n                        },\r\n                        checkCategory : function(event) {\r\n                        \tnode  \t= event.memo.node;\r\n                        \tcontainer = event.target.up('div.chooser_container');\r\n                        \tvalue \t= container.down('input[type=\"text\"].entities').value.strip();\r\n                        \tif (node.attributes.checked) {\r\n                            \tif (value) ids = value.split(',');\r\n                            \telse ids = [];\r\n                            \tif (-1 == ids.indexOf(node.id)) {\r\n                                    ids.push(node.id);\r\n                                    container.down('input[type=\"text\"].entities').value = ids.join(',');\r\n                            \t}\r\n                        \t} else {\r\n                            \tids = value.split(',');\r\n                            \twhile (-1 != ids.indexOf(node.id)) {\r\n                                    ids.splice(ids.indexOf(node.id), 1);\r\n                                    container.down('input[type=\"text\"].entities').value = ids.join(',');\r\n                            \t}\r\n                        \t}\r\n                        }\r\n  \t              }\r\n \r\n                    window.MultiCategoryChooser = MultiCategoryChooser;\r\n                    jQuery(function() {\r\n                        var container = $('{$htmlId}-container');\r\n                        if (container) {\r\n                            container.up(0).down('.control-value').hide();\r\n                        }\r\n \r\n                        Event.observe(document, 'node:changed', function(event){\r\n                            MultiCategoryChooser.checkCategory(event);\r\n                        });\r\n                        Event.observe(document, 'category:beforeLoad', function(event) {\r\n                        \tcontainer = event.target.up('div.chooser_container');\r\n                        \tvalue \t= container.down('input[type=\"text\"].entities').value.strip();\r\n                            event.memo.treeLoader.baseParams.selected = value;\r\n                        });\r\n                    });\r\n                });\r\n            &lt;\/script&gt;\r\nHTML;\r\n \r\n    \treturn $return;\r\n\t}\r\n<\/pre>\n<p>So, this is the Multi Category Chooser. But what if we need only one category? For such case there is a ready-made solution available, so we do not need to invent anything new:<\/p>\n<pre class=\"lang:php decode:true \">&lt;parameter name=\"category\" xsi:type=\"block\" visible=\"true\" required=\"true\" sort_order=\"10\"&gt;\r\n\t&lt;label translate=\"true\"&gt;Category&lt;\/label&gt;\r\n\t&lt;block class=\"Magento\\Catalog\\Block\\Adminhtml\\Category\\Widget\\Chooser\"&gt;\r\n        &lt;data&gt;\r\n            &lt;item name=\"button\" xsi:type=\"array\"&gt;\r\n                &lt;item name=\"open\" xsi:type=\"string\" translate=\"true\"&gt;Select Category...&lt;\/item&gt;\r\n            &lt;\/item&gt;\r\n        &lt;\/data&gt;\r\n    &lt;\/block&gt;\r\n&lt;\/parameter&gt;\r\n<\/pre>\n<p>This solution I have applied for one of my widgets, but it is also possible to adapt it for configuring various form elements.<\/p>\n<div class=\"module_in_content_container\"><a href=\"https:\/\/store.belvg.com\/groups-catalog.html\" class=\"link_to_module\" target=\"_blank\" rel=\"noopener\"><\/a><div class=\"module_content\"><img src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2018\/10\/groups_catalog.png\" width=\"450\" height=\"450\" alt=\"groups_catalog\" class=\"module_image\" title=\"A &ldquo;Category Chooser&rdquo; in Magento 2 Backend\"><div class=\"module_content_part\"><h3 class=\"title\">Groups Catalog for Magento 2<\/h3><p class=\"module_content_text\">Take your online store to the next level with BelVG module<\/p><a href=\"https:\/\/store.belvg.com\/groups-catalog.html\" class=\"link_2_to_module\" target=\"_blank\" style=\"display:inline-block\" rel=\"noopener\"><span class=\"read-more\">Download here<\/span><\/a><\/div><\/div><\/div>\n<p>Want to keep track of your store&rsquo;s unregistered users? Download our free <a href=\"https:\/\/store.belvg.com\/guests-catalog.html\" target=\"_blank\" rel=\"noopener\">Magento&nbsp;Guests Catalog<\/a> extension.<\/p>\n\n","protected":false},"excerpt":{"rendered":"Let&#8217;s imagine, you need to create a category chooser for magento admin panel. For example, &#8230;","protected":false},"author":22,"featured_media":12641,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,389,524],"tags":[],"class_list":["post-12639","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-magento","category-magento2-development","category-magento-speed-optimization","post_format-post-format-image"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Let&#039;s imagine, you need to create a category chooser for magento admin panel. For example, this might be necessary in the following cases: 1. To be used for some standard form as follows:\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Mikhail Soiko\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#article\",\"name\":\"A \\u201cCategory Chooser\\u201d in Magento 2 Backend | BelVG Blog\",\"headline\":\"A \\u201cCategory Chooser\\u201d in Magento 2 Backend\",\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/03\\\/category-chooser-Magento-2.jpg\",\"width\":770,\"height\":209,\"caption\":\"A \\u201cCategory chooser\\u201d in Magento 2 backend\"},\"datePublished\":\"2017-03-16T13:31:02+02:00\",\"dateModified\":\"2019-09-18T17:45:57+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":15,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#webpage\"},\"articleSection\":\"Magento, Magento 2 Development, Magento Speed Optimization, Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"position\":2,\"name\":\"Magento\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#listItem\",\"name\":\"A \\u201cCategory Chooser\\u201d in Magento 2 Backend\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#listItem\",\"position\":3,\"name\":\"A \\u201cCategory Chooser\\u201d in Magento 2 Backend\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko\",\"name\":\"Mikhail Soiko\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1603d45135617d53877de2d9ffe112a497830fa8a92f16dd13b43069b1e53482?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Mikhail Soiko\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#webpage\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html\",\"name\":\"A \\u201cCategory Chooser\\u201d in Magento 2 Backend | BelVG Blog\",\"description\":\"Let's imagine, you need to create a category chooser for magento admin panel. For example, this might be necessary in the following cases: 1. To be used for some standard form as follows:\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/mishell-soiko#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/03\\\/category-chooser-Magento-2.jpg\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html\\\/#mainImage\",\"width\":770,\"height\":209,\"caption\":\"A \\u201cCategory chooser\\u201d in Magento 2 backend\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/a-category-chooser-in-magento-2-backend.html#mainImage\"},\"datePublished\":\"2017-03-16T13:31:02+02:00\",\"dateModified\":\"2019-09-18T17:45:57+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"A \u201cCategory Chooser\u201d in Magento 2 Backend | BelVG Blog","description":"Let's imagine, you need to create a category chooser for magento admin panel. For example, this might be necessary in the following cases: 1. To be used for some standard form as follows:","canonical_url":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#article","name":"A \u201cCategory Chooser\u201d in Magento 2 Backend | BelVG Blog","headline":"A \u201cCategory Chooser\u201d in Magento 2 Backend","author":{"@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author"},"publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2017\/03\/category-chooser-Magento-2.jpg","width":770,"height":209,"caption":"A \u201cCategory chooser\u201d in Magento 2 backend"},"datePublished":"2017-03-16T13:31:02+02:00","dateModified":"2019-09-18T17:45:57+02:00","inLanguage":"en-US","commentCount":15,"mainEntityOfPage":{"@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#webpage"},"isPartOf":{"@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#webpage"},"articleSection":"Magento, Magento 2 Development, Magento Speed Optimization, Image"},{"@type":"BreadcrumbList","@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/belvg.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","position":2,"name":"Magento","item":"https:\/\/belvg.com\/blog\/category\/magento","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#listItem","name":"A \u201cCategory Chooser\u201d in Magento 2 Backend"},"previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#listItem","position":3,"name":"A \u201cCategory Chooser\u201d in Magento 2 Backend","previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}}]},{"@type":"Organization","@id":"https:\/\/belvg.com\/blog\/#organization","name":"BelVG Blog","description":"Magento and Prestashop articles","url":"https:\/\/belvg.com\/blog\/"},{"@type":"Person","@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author","url":"https:\/\/belvg.com\/blog\/author\/mishell-soiko","name":"Mikhail Soiko","image":{"@type":"ImageObject","@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/1603d45135617d53877de2d9ffe112a497830fa8a92f16dd13b43069b1e53482?s=96&d=mm&r=g","width":96,"height":96,"caption":"Mikhail Soiko"}},{"@type":"WebPage","@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#webpage","url":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html","name":"A \u201cCategory Chooser\u201d in Magento 2 Backend | BelVG Blog","description":"Let's imagine, you need to create a category chooser for magento admin panel. For example, this might be necessary in the following cases: 1. To be used for some standard form as follows:","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/belvg.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#breadcrumblist"},"author":{"@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author"},"creator":{"@id":"https:\/\/belvg.com\/blog\/author\/mishell-soiko#author"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2017\/03\/category-chooser-Magento-2.jpg","@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html\/#mainImage","width":770,"height":209,"caption":"A \u201cCategory chooser\u201d in Magento 2 backend"},"primaryImageOfPage":{"@id":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html#mainImage"},"datePublished":"2017-03-16T13:31:02+02:00","dateModified":"2019-09-18T17:45:57+02:00"},{"@type":"WebSite","@id":"https:\/\/belvg.com\/blog\/#website","url":"https:\/\/belvg.com\/blog\/","name":"BelVG Blog","description":"Magento and Prestashop articles","inLanguage":"en-US","publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"12639","title":"A \u201cCategory Chooser\u201d in Magento 2 Backend | #site_title","description":"Let's imagine, you need to create a category chooser for magento admin panel. For example, this might be necessary in the following cases:\r\n1. To be used for some standard form as follows:","keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 18:37:21","updated":"2026-11-03 18:37:21"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/category\/magento\" title=\"Magento\">Magento<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tA \u201cCategory Chooser\u201d in Magento 2 Backend\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/belvg.com\/blog\/"},{"label":"Magento","link":"https:\/\/belvg.com\/blog\/category\/magento"},{"label":"A \u201cCategory Chooser\u201d in Magento 2 Backend","link":"https:\/\/belvg.com\/blog\/a-category-chooser-in-magento-2-backend.html"}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/12639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/comments?post=12639"}],"version-history":[{"count":-2,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/12639\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media\/12641"}],"wp:attachment":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media?parent=12639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/categories?post=12639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/tags?post=12639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}