{"id":415356,"date":"2023-12-21T07:14:55","date_gmt":"2023-12-21T07:14:55","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=415356"},"modified":"2023-12-21T07:41:50","modified_gmt":"2023-12-21T07:41:50","slug":"how-to-add-a-custom-php-modifier-in-the-ui-component","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/","title":{"rendered":"How to add a custom PHP modifier in the UI Component"},"content":{"rendered":"\n<p>Using modifiers is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks.<\/p>\n\n\n\n<p>Example: In cases We need additional data should be loaded from the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation of custom PHP modifier<\/h2>\n\n\n\n<p>Use the following steps to implement a custom PHP modifier for a UI component;<\/p>\n\n\n\n<p><strong>Step 1:<\/strong><\/p>\n\n\n\n<p>In your custom module create a class that implements&nbsp;<a href=\"https:\/\/github.com\/magento\/magento2\/blob\/2.4\/app\/code\/Magento\/Ui\/DataProvider\/Modifier\/ModifierInterface.php\" target=\"_blank\" rel=\"noreferrer noopener\"><code>\\Magento\\Ui\\DataProvider\\Modifier\\ModifierInterface<\/code><\/a>&nbsp;with the following methods:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nuse Magento\\Ui\\DataProvider\\Modifier\\ModifierInterface;\n\nclass Example implements ModifierInterface\n{\n    public function modifyMeta(array $meta)\n    {\n        $meta['test_fieldset_name'] = [\n            'arguments' =&gt; [\n                'data' =&gt; [\n                    'config' =&gt; [\n                        'label' =&gt; __('Test Label For Fieldset'),\n                        'sortOrder' =&gt; 50,\n                        'collapsible' =&gt; true\n                    ]\n                ]\n            ],\n            'children' =&gt; [\n                'test_field_name' =&gt; [\n                    'arguments' =&gt; [\n                        'data' =&gt; [\n                            'config' =&gt; [\n                                'formElement' =&gt; 'select',\n                                'componentType' =&gt; 'field',\n                                'options' =&gt; [\n                                    ['value' =&gt; 'test_value', 'label' =&gt; 'Test Value'],\n                                    ],\n                                'visible' =&gt; 1,\n                                'required' =&gt; 1,\n                                'label' =&gt; __('Label For Element')\n                            ]\n                        ]\n                    ]\n                ]\n            ]\n        ];\n\n        return $meta;\n    }\n\n    \/**\n     * {@inheritdoc}\n     *\/\n    public function modifyData(array $data)\n    {\n        return $data;\n    }\n}\n<\/pre>\n<cite><strong>Step 2:<\/strong><\/cite><\/blockquote>\n\n\n\n<p>Declare modifier in <code>&lt;Your_Module_dir&gt;\/etc\/adminhtml\/di.xml<\/code>. This declaration looks like the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;virtualType name=\"%Webkul\\Test\\DataProvider\\Modifier\\Pool%\" type=\"Magento\\Ui\\DataProvider\\Modifier\\Pool\"&gt;\n     &lt;arguments&gt;\n         &lt;argument name=\"modifiers\" xsi:type=\"array\"&gt;\n             &lt;item name=\"modifier_name\" xsi:type=\"array\"&gt;\n                 &lt;item name=\"class\" xsi:type=\"string\"&gt;%Webkul\\Test\\Modifier\\Example%&lt;\/item&gt;\n                 &lt;item name=\"sortOrder\" xsi:type=\"number\"&gt;10&lt;\/item&gt;\n             &lt;\/item&gt;\n         &lt;\/argument&gt;\n     &lt;\/arguments&gt;\n&lt;\/virtualType&gt;\n<\/pre>\n\n\n\n<p><code>Webkul\\Test\\DataProvider\\Modifier\\Pool<\/code>&nbsp;is a&nbsp;virtual class.<\/p>\n\n\n\n<p><strong>Step 3:<\/strong><\/p>\n\n\n\n<p>To use your modifier, add a dependency on\u00a0your UI component data provider.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;type name=\"%Webkul\\Test\\Ui\\DataProvider\\Example%\"&gt;\n    &lt;arguments&gt;\n        &lt;argument name=\"pool\" xsi:type=\"object\"&gt;%Webkul\\Test\\DataProvider\\Modifier\\Pool%&lt;\/argument&gt;\n    &lt;\/arguments&gt;\n&lt;\/type&gt;\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using modifiers is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks. Example: In cases We need additional data should be loaded from the database. Implementation of custom PHP modifier Use the following steps to implement a custom PHP modifier for a UI component; Step 1: <a href=\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":497,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-415356","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to add a custom PHP modifier in the UI Component<\/title>\n<meta name=\"description\" content=\"Using PHP Modifier is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add a custom PHP modifier in the UI Component\" \/>\n<meta property=\"og:description\" content=\"Using PHP Modifier is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:author\" content=\"pammu23\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-21T07:14:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-21T07:41:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Pramod Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pramod Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\"},\"author\":{\"name\":\"Pramod Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590\"},\"headline\":\"How to add a custom PHP modifier in the UI Component\",\"datePublished\":\"2023-12-21T07:14:55+00:00\",\"dateModified\":\"2023-12-21T07:41:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\"},\"wordCount\":110,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\",\"name\":\"How to add a custom PHP modifier in the UI Component\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2023-12-21T07:14:55+00:00\",\"dateModified\":\"2023-12-21T07:41:50+00:00\",\"description\":\"Using PHP Modifier is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add a custom PHP modifier in the UI Component\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590\",\"name\":\"Pramod Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Pramod Kumar\"},\"description\":\"Software Engineer\",\"sameAs\":[\"pammu23\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/pramodkumar-mg592\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add a custom PHP modifier in the UI Component","description":"Using PHP Modifier is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/","og_locale":"en_US","og_type":"article","og_title":"How to add a custom PHP modifier in the UI Component","og_description":"Using PHP Modifier is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks","og_url":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_author":"pammu23","article_published_time":"2023-12-21T07:14:55+00:00","article_modified_time":"2023-12-21T07:41:50+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Pramod Kumar","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Pramod Kumar","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/"},"author":{"name":"Pramod Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590"},"headline":"How to add a custom PHP modifier in the UI Component","datePublished":"2023-12-21T07:14:55+00:00","dateModified":"2023-12-21T07:41:50+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/"},"wordCount":110,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/","url":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/","name":"How to add a custom PHP modifier in the UI Component","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2023-12-21T07:14:55+00:00","dateModified":"2023-12-21T07:41:50+00:00","description":"Using PHP Modifier is optional and might be necessary when static declaration in XML configuration files is not suitable for the tasks","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-add-a-custom-php-modifier-in-the-ui-component\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add a custom PHP modifier in the UI Component"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/285932e5fa620be1f718b1f68c6af590","name":"Pramod Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/35653d7d513cf4c67589b5296b21e3eeac45915b287bac2c509616f2849984a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Pramod Kumar"},"description":"Software Engineer","sameAs":["pammu23"],"url":"https:\/\/webkul.com\/blog\/author\/pramodkumar-mg592\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/415356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/497"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=415356"}],"version-history":[{"count":11,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/415356\/revisions"}],"predecessor-version":[{"id":415371,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/415356\/revisions\/415371"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=415356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=415356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=415356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}