<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marco Guiducci on Medium]]></title>
        <description><![CDATA[Stories by Marco Guiducci on Medium]]></description>
        <link>https://medium.com/@marco.guiducci23?source=rss-42d1070e5485------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1ctCBiMFZEe2IGiR</url>
            <title>Stories by Marco Guiducci on Medium</title>
            <link>https://medium.com/@marco.guiducci23?source=rss-42d1070e5485------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 23:49:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marco.guiducci23/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Pimcore Tips-N-Tricks — Chapter 2: Create Custom Operators for DataImporter]]></title>
            <link>https://medium.com/@marco.guiducci23/pimcore-tips-n-tricks-chapter-2-create-custom-operators-for-dataimporter-3a59fda0e246?source=rss-42d1070e5485------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a59fda0e246</guid>
            <category><![CDATA[import]]></category>
            <category><![CDATA[pimcore-development]]></category>
            <category><![CDATA[pimcore]]></category>
            <category><![CDATA[pim]]></category>
            <category><![CDATA[data-import-and-export]]></category>
            <dc:creator><![CDATA[Marco Guiducci]]></dc:creator>
            <pubDate>Sun, 12 Nov 2023 10:49:21 GMT</pubDate>
            <atom:updated>2023-11-12T10:49:21.102Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pimcore Tips-N-Tricks — Chapter 2: Create Custom Operators for DataImporter</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*MPKQdNZlFZmM2ugajmisog.png" /></figure><p>Hello and welcome to a new chapter of “Marco Guiducci presents: Pimcore Tips-N-Tricks” (If you have read that with Sheldon’s voice, you are 50% completed with this tutorial).</p><p>Ok, maybe the introduction was too much “podcast style”, but this is exactly the format that I want for this series of articles: not a manual, not tedious documentation, but just some tips to share my knowledge on “<a href="https://www.youtube.com/watch?v=Y-CsIqTFEyY&amp;ab_channel=HowToBasic">how to basic</a>”, to face the everyday tasks.</p><p>In the previous chapter, we talked about <a href="https://medium.com/@marco.guiducci23/pimcore-tips-n-tricks-chapter-1-adding-a-custom-menu-item-49052f16239c">how to add a custom menu item</a>; this time, we will talk about creating custom operators for Pimcore’s Data Importer.</p><h3>The DataImporter Bundle</h3><p>If you are reading this article, we can suppose that you know what <a href="https://github.com/pimcore/data-importer">Pimcore’s DataImport bundle</a> is (if not, it means that you just like what I write so thank you very much!).</p><p>By the way, just as a recap, starting from the later Pimcore 6.9 version and then officially in Pimcore X, the DataImporter bundle replaced the original “CSV Import” functionality, adding support for a lot of new import modalities, formats, resolver strategy and a bunch of ready-to-use operators to manipulate source data.</p><p>Even if this can be useless, I just want to remind you that in Pimcore 11 the bundle installation procedure has changed a bit, so I’ll give you a brief reminder of how to install a bundle.</p><p>As the first step, you must include the bundle in your project, running:</p><pre>composer require pimcore/data-importer</pre><p>Then, you must add bundle reference to the bundles.php file in the config folder; keep in mind that it’s not sufficient to add the reference to that bundle only, but you must also declare the dependent DataHub bundle to let things work:</p><pre>use Pimcore\Bundle\DataHubBundle\PimcoreDataHubBundle;<br>use Pimcore\Bundle\DataImporterBundle\PimcoreDataImporterBundle;<br><br>return [<br>    PimcoreDataHubBundle::class =&gt; [&#39;all&#39; =&gt; true],<br>    PimcoreDataImporterBundle::class =&gt; [&#39;all&#39; =&gt; true],<br>];</pre><p>Finally, you can install the bundle running:</p><pre>bin/console pimcore:bundle:install PimcoreDataImporterBundle</pre><p>As I previously mentioned in the introduction paragraph, I don’t want to give you a 100% explanation of all features, for that you can always refer to the <a href="https://github.com/pimcore/data-importer/blob/1.x/doc/03_Configuration/06_Mapping_Configuration/02_Transformation_Pipeline.md">official documentation</a>.</p><p>My goal is always the same: how to develop some stuff to face everyday tasks and problems. That is because, unless you are very lucky, your customer will never give you a massive amount of data that is ready to import after a simple importer configuration.</p><p>In concrete scenarios, you may need to create an object before relating it to the product that you are importing, and you would like to do that without creating different import configurations. In this case (and other one hundred examples I could give) you need to implement a custom operator.</p><h3>Building the Extensions</h3><p>As the <a href="https://github.com/pimcore/data-importer/blob/1.x/doc/06_Extending/01_Extend_Custom_Strategies.md">documentation</a> says, you can create a custom extension for any of the following topics:</p><ul><li>Data Sources</li><li>File Formats</li><li>Resolver Loading Strategies</li><li>Element Location Strategies</li><li>Element Publishing Strategies</li><li>Cleanup Strategies</li><li>Transformation Pipeline Operators</li><li>Data Targets</li></ul><p>Reading that doc, you are full of expectations and ready to know how you can develop something concretely, but then you read:</p><blockquote>Have a look at the current implementations to see how things are working.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*IdVEgJ2UWNd5pJSBrSBTtg.jpeg" /><figcaption>My Goodness Why Didn’t I Think of That</figcaption></figure><p>Keep calm, I will not conclude this article by saying: “ok, now you can start to reverse engineering for all steps”. Let’s follow the right order to develop something custom.</p><p>In this article, I will provide a simple example of a “Transformation Pipeline Operator” that takes the source data and does some case conversion tricks.</p><h4>PHP Implementation</h4><p>The first step is to create the business logic for your operator; you must start by extending the “AbstractOperator” class. To accomplish your goal, you must implement 3 functions:</p><p>The first is the “setSettings” function; in that function, you can map parameters that will come from the request.</p><pre>/**<br> * @var string<br> */<br>protected $caseConversion;<br><br>public function setSettings(array $settings): void<br>{<br>    $this-&gt;caseConversion = $settings[&#39;caseConversion&#39;] ?? &#39;strtolower&#39;;<br>}</pre><p>In this specific case, the desired “case conversion” operation is selected by the user; we will see it later.</p><p>Then, you must implement the “process” function; this is the core of the business logic:</p><pre>public function process($inputData, bool $dryRun = false)<br>{<br>    $returnScalar = false;<br>    if (!is_array($inputData)) {<br>        $returnScalar = true;<br>        $inputData = [$inputData];<br>    }<br><br>    $result = [];<br>    foreach ($inputData as &amp;$data) {<br>        $result[] = ($this-&gt;caseConversion)($data);<br>    }<br><br>    if ($returnScalar) {<br>        if (!empty($result)) {<br>            return reset($result);<br>        }<br><br>        return null;<br>    } else {<br>        return $result;<br>    }<br>}</pre><p>In that example, the logic is very easy: we just apply the case operation selected by the user to the source data.</p><p>It’s important to note that input can be scalar if only one cell is selected, or multiple; this concept is also very important in defineing the return type, as it’s crucial to let Pimcore know which attributes can be filled by the result of the operation.</p><pre>public function evaluateReturnType(string $inputType, int $index = null): string<br>{<br>    if (!in_array($inputType, [TransformationDataTypeService::DEFAULT_TYPE, TransformationDataTypeService::DEFAULT_ARRAY])) {<br>        throw new InvalidConfigurationException(sprintf(&quot;Unsupported input type &#39;%s&#39; for simple test operator at transformation position %s&quot;, $inputType, $index));<br>    }<br><br>    return $inputType;<br>}</pre><h4>Register Implementation as a Symfony Service</h4><p>After having completed the logic, is crucial to register the service in Symfony:</p><pre>services:<br>    #<br>    # EVENT LISTENER<br>    #<br>    App\EventListener\PimcoreAdminListener:<br>        tags:<br>            - { name: kernel.event_listener, event: pimcore.bundle_manager.paths.css, method: addCSSFiles }<br>            - { name: kernel.event_listener, event: pimcore.bundle_manager.paths.js, method: addJSFiles }<br><br>    #<br>    # DATA-IMPORTER<br>    #<br>    App\Mapping\Operator\Simple\CaseConversion:<br>        tags:<br>            - { name: &quot;pimcore.datahub.data_importer.operator&quot;, type: &quot;caseConversion&quot; }</pre><p>Please note that we need also the “PimcoreAdminListener” to load JavaScript files.</p><h4>JavaScript Implementation</h4><p>To implement the component appearance, it’s sufficient to develop a component that extends the specific class you want to extend:</p><pre>pimcore.registerNS(&quot;pimcore.plugin.pimcoreDataImporterBundle.configuration.components.mapping.operator.caseConversion&quot;);<br>pimcore.plugin.pimcoreDataImporterBundle.configuration.components.mapping.operator.caseConversion = Class.create(pimcore.plugin.pimcoreDataImporterBundle.configuration.components.mapping.abstractOperator, {<br><br>    type: &#39;caseConversion&#39;,<br><br>    getFormItems: function () {<br>        return [<br>            {<br>                xtype: &#39;combo&#39;,<br>                fieldLabel: t(&#39;plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_mode&#39;),<br>                value: this.data.settings ? this.data.settings.caseConversion : &#39;strtolower&#39;,<br>                name: &#39;settings.caseConversion&#39;,<br>                listeners: {<br>                    change: this.inputChangePreviewUpdate.bind(this)<br>                },<br>                store: [<br>                    [&#39;strtolower&#39;, t(&#39;plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_strtolower&#39;)],<br>                    [&#39;strtoupper&#39;, t(&#39;plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_strtoupper&#39;)],<br>                    [&#39;ucfirst&#39;, t(&#39;plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_ucfirst&#39;)],<br>                    [&#39;ucwords&#39;, t(&#39;plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_ucwords&#39;)]<br>                ]<br><br>            }<br>        ];<br>    }<br><br>});</pre><p>Please note that the “type” parameter must be the same as the tag declared in the Symfony service.</p><p>The “getFormItems” function, simply defines the form items that appear for the component; in that case, a simple combo box with fixed elements is shown, but you can add anything that is required for your needs.</p><p>In the following image, you can see the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*6cdOj783AGEDkjy7SfVJuw.png" /></figure><h3>What to Take Home</h3><p>In this article, we have seen how to implement a simple DataImporter pipeline operator.</p><p>Although documentation gives you some tips to proceed on your own, a lot of reverse engineering is required to be sure you have all your ingredients for your receipt; since I have already faced that phase, let’s say that this is the receipt as in your favorite food blog (sorry, for this metaphor, but it’s lunchtime for me and I’m starting craving).</p><p>You can use this article as a guide to implementing all the other kinds of extensions, and if you want you can share that with me by commenting on that article.</p><p>In the next chapter, we will see how to produce some semi-automated output starting from our products’ data.</p><p>Thanks for watch… ouch, to have read this article!</p><h3>References</h3><ul><li><a href="https://pimcore.com/docs/platform/">Pimcore Official Documentation</a></li><li><a href="https://github.com/MarcoGuiducci/pimcore-Tips-n-Tricks-DataImporter">Source Code for this Article</a></li><li><a href="https://www.amazon.it/Modernizing-Enterprise-CMS-Using-Pimcore/dp/1801075409/">My Published Book about Pimcore</a></li><li><a href="https://medium.com/@marco.guiducci23/pimcore-tips-n-tricks-chapter-1-adding-a-custom-menu-item-49052f16239c">Chapter 1: Adding a Custom Menu Item</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a59fda0e246" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pimcore Tips-N-Tricks - Chapter 1: Adding a Custom Menu Item]]></title>
            <link>https://medium.com/@marco.guiducci23/pimcore-tips-n-tricks-chapter-1-adding-a-custom-menu-item-49052f16239c?source=rss-42d1070e5485------2</link>
            <guid isPermaLink="false">https://medium.com/p/49052f16239c</guid>
            <category><![CDATA[pimcore-development]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[pimcore]]></category>
            <category><![CDATA[extjs]]></category>
            <dc:creator><![CDATA[Marco Guiducci]]></dc:creator>
            <pubDate>Sat, 04 Nov 2023 14:46:43 GMT</pubDate>
            <atom:updated>2023-11-04T14:46:43.207Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6Db6_JUP9Ulm0Hcd" /><figcaption>Photo by <a href="https://unsplash.com/@florianolv?utm_source=medium&amp;utm_medium=referral">Florian Olivo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>During my last five years working, I was mostly focused on developing custom solutions for my customers with Pimcore.</p><p>As any developer may confirm, although you are using the same technology and patterns for different projects, every customer is different and, consequently, every project is unique.</p><p>Even if the previous sentence is true, at the same time we can affirm that, usually, we are facing a situation for which we need to re-implement some piece of logic that we already have coded before.</p><p>This is exactly my everyday story; interface customization, some magic button that “can do something”, import/export facilities, and so on… all things that let me say:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h1T6FrF_GI4z15Ob0hR0fQ.jpeg" /></figure><p>After the fifth time that I needed to open an old project (after having spent minutes thinking about “which” project I implemented a feature before) to retrieve some pieces of code, I said to myself: “OK, I must share that with someone.”</p><p>So here we are, with my first chapter about Pimcore “Tips-N-Tricks”; in this chapter, we will discuss how to create a simple custom menu to add to the main toolbar.</p><p>Before starting, I want to say that I’ve not created something brand-new; this article, and the following ones, are just “putting together” information due to documentation lack and reverse engineering needed to produce concrete features, with the hope that this will save time for someone like me.</p><p>If I caught your curiosity, I hope you will also have a look at <a href="https://www.amazon.it/Modernizing-Enterprise-CMS-Using-Pimcore/dp/1801075409/">my published book about Pimcore</a> written in collaboration with <a href="https://medium.com/u/97d01fcd4684">Daniele Fontani</a> and <a href="https://medium.com/u/a292b64fb2d8">Francesco Minà</a>.</p><h3><strong>What’s on the pot?</strong></h3><p>As the title of this article said, the main topic is Pimcore; so, you will forgive me if I suppose that everyone interested in this article already knows what Pimcore is and how it works, so I will not spend words on that.</p><p>Having said that, I have prepared a self-contained repository that contains the Pimcore installation and all the logic we will discuss in the following chapters.</p><p>So, the road map of the article will be the following:</p><ul><li>How to install the repository</li><li>Creating the context for the menu</li><li>How to implement the JavaScript stuff</li><li>How to serve the menu from the backend</li></ul><h3>Install and Configure Pimcore</h3><p>As previously mentioned, in the references at the bottom of the article you will find a repository with the source code. The repository is simply based on the dockerized Pimcore Skeleton project.</p><p>To install and configure the repository, just follow the instructions on the Readme file, so just open a shell and type:</p><pre>docker-compose up -d<br>docker-compose exec php bash restore.sh</pre><p>This script automatically restores vendor packages, installs assets, and performs a cache warm-up.<br>This also provides an already configured database with some data.</p><p>Credentials for Pimcore admin are `pimcore/pimcore`.</p><h3>Presenting the Context</h3><p>Let’s start by giving a concrete context for what we are going to realize; in a recent project, a customer positioned in the manufacturing industry asked me to create a menu in which he could manage the conversion between “squared millimeters” and “AWG” for some section attributes.</p><p>If you don’t know what AWG is don’t be afraid, as it was my first reaction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*hxBOJzPxJpkux7nhd3_-kg.jpeg" /></figure><p>I don’t want to bother you with details, but if you are curious AWG stands for “<a href="https://it.wikipedia.org/wiki/American_wire_gauge">American wire gauge</a>”, an alternative measurement system to express cables and wire section.</p><p>Now that we have the context, let’s start coding some code!</p><h3>Mixing the Potion Ingredients</h3><p>Now that we know what’s in the pot, it’s to prepare the ingredients and mix them.</p><h4>Create a Custom Table on the Database</h4><p>The quickest way to create a custom table on the Pimcore database is obviously to create it in the database administrator; but, in concrete scenarios in which you have development, test, and production environments, you will have to repeat the operation manually.</p><p>To avoid the need to repeat actions manually, you can generate a Migration; in the <a href="https://pimcore.com/docs/platform/Pimcore/Development_Tools_and_Details/Migrations/">Pimcore documentation</a>, you will find the commands to generate and execute the migration and other useful configurations to automatically run migrations on your project.</p><p>Once you have generated a new migration, you can implement the “up” function; let’s see the code snippet:</p><pre>final class Version20231030132309 extends AbstractMigration<br>{<br>    private $tablesToInstall = [<br>        &#39;mm2_to_awg_conversion&#39; =&gt;<br>            &quot;CREATE TABLE IF NOT EXISTS `mm2_to_awg_conversion` (<br>                `id` int(11) NOT NULL AUTO_INCREMENT,<br>                `mm2` decimal(10,2) DEFAULT NULL,<br>                `awg` varchar(255) DEFAULT NULL,<br>                PRIMARY KEY (`id`)<br>            ) ENGINE=InnoDB <br>            DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;&quot;<br>    ];<br><br>    public function up(Schema $schema): void<br>    {<br>        foreach ($this-&gt;tablesToInstall as $name =&gt; $statement) {<br>            if ($schema-&gt;hasTable($name)) {<br>                continue;<br>            }<br><br>            $this-&gt;addSql($statement);<br>        }<br><br>    }<br>}</pre><p>In the snippet above, you can see how easy adding a new table to the schema is; in my experience, I usually create an array variable having table names as keys and the creation statement as value; this is useful also for creating installers.</p><h4>JavaScript event to render the menu</h4><p>If your goal is the creation of a custom menu, the first thing that you need to do is to add the menu item to the toolbar and render it on the main panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHmtt89NpiBEC607cHFfVg.jpeg" /><figcaption>OK, maybe it could be a bit obvious…</figcaption></figure><p>In the new Pimcore 11 version, adding a custom item to the menu was made simpler than in the previous versions; as reported in <a href="https://pimcore.com/docs/platform/Pimcore/Extending_Pimcore/Bundle_Developers_Guide/Event_Listener_UI/#adding-custom-main-navigation-items">Pimcore documentation</a>, you only need to implement an event listener for the “preMenuBuild” UI event and add a new item.</p><p>Let’s start creating a “startup.js” file inside the “public” folder if you want to add your menu directly in the project, or inside the “Resource” folder if you’re doing it inside a bundle.</p><pre>pimcore.registerNS(&quot;pimcore.plugin.CustomMenu&quot;);<br><br>pimcore.plugin.CustomMenu = Class.create({<br>    initialize: function () {<br>        document.addEventListener(pimcore.events.preMenuBuild, this.preMenuBuild.bind(this));    <br>    },<br><br>    preMenuBuild: function (e) {<br>        // the event contains the existing menu<br>        let menu = e.detail.menu;<br><br>        // the property name is used as id with the prefix pimcore_menu_ in the html markup e.g. pimcore_menu_mybundle<br>        menu.custommenu = {<br>            label: t(&#39;Custom Settings&#39;), // set your label here, will be shown as tooltip<br>            iconCls: &#39;pimcore_nav_icon_properties&#39;, // set full icon name here<br>            priority: 42, // define the position where you menu should be shown. Core menu items will leave a gap of 10 custom main menu items<br>            items: [], //if your main menu has subitems please see Adding Custom Submenus To ExistingNavigation Items <br>            shadow: false,<br>            handler: this.openCustomMenu, // defining a handler will override the standard &quot;showSubMenu&quot; functionality, use in combination with &quot;noSubmenus&quot;<br>            noSubmenus: true, // if there are no submenus set to true otherwise menu won&#39;t show up<br>            cls: &quot;pimcore_navigation_flyout&quot;, // use pimcore_navigation_flyout if you have subitems<br>        };<br>    },<br><br>    openCustomMenu: function(element) {<br>        try {<br>            pimcore.globalmanager.get(&quot;plugin_pimcore_custommenu&quot;).activate();<br>        } catch (e) {<br>            pimcore.globalmanager.add(&quot;plugin_pimcore_custommenu&quot;, new pimcore.plugin.CustomMenu.settings());<br>        }<br>    }<br>});<br><br>var CustomMenuPlugin = new pimcore.plugin.CustomMenu();</pre><p>By now, nothing more and nothing less than what is shown in the documentation. This script just adds a new icon in the main menu, but it doesn’t do anything else; how to effectively render a menu to do something concrete?</p><p>The documentation is lacking at this point, and this is the main reason that pushed me to write this kind of article: avoid to other developers spending hours of reverse engineering to find out how others did things.</p><p>So, let’s see how to effectively render the menu; for practicing reasons, I have created a second script named “settings.js” (but you can choose any name) to put the logic in. Let’s see some crucial steps:</p><pre>pimcore.registerNS(&quot;pimcore.plugin.CustomMenu.settings&quot;);<br><br>pimcore.plugin.CustomMenu.settings = Class.create({<br><br>    activate: function () {<br>        var tabPanel = Ext.getCmp(&#39;pimcore_panel_tabs&#39;);<br>        <br>        if(tabPanel.items.keys.indexOf(&quot;custommenu_settings&quot;) &gt; -1){<br>            tabPanel.setActiveItem(&#39;custommenu_settings&#39;);<br>        }else{<br>            throw &quot;need to reload&quot;;<br>        }<br>    },<br><br>    initialize: function () {<br>        this.getData();<br>    },<br><br>    getData: function () {<br>        Ext.Ajax.request({<br>            url: &#39;/admin/custom-menu/get-custommenu-settings-attributes&#39;,<br>            success: function (response) {<br>                this.data = Ext.decode(response.responseText).data;<br>                this.getTabPanel();<br>            }.bind(this)<br>        });<br>    },<br><br>    getTabPanel: function () {<br>        //Stay Tuned...<br>    }<br>});</pre><p>As you can see in the snippet above, the first function is the “activate” one; this function checks if the menu is already opened in a panel in the main section, otherwise, it requires to reload it. Please note that this function is called by the previous script.</p><p>The “initialize” function is the constructor one; it just calls the function that calls the controller to get the data to be shown (we will see it later). After the data are retrieved, the “getPanelData” function is called to show them.</p><pre>getTabPanel: function () {<br>    if (!this.panel) {<br>        var self = this;<br><br>        this.panel = Ext.create(&#39;Ext.panel.Panel&#39;, {<br>            id: &#39;custommenu_settings&#39;,<br>            title: t(&#39;Custom Settings&#39;),<br>            iconCls: &#39;pimcore_icon_system&#39;,<br>            border: false,<br>            layout: &#39;fit&#39;,<br>            closable: true<br>        });<br><br>        var tabPanel = Ext.getCmp(&#39;pimcore_panel_tabs&#39;);<br>        tabPanel.add(this.panel);<br>        tabPanel.setActiveItem(&#39;custommenu_settings&#39;);<br><br>        var mm2AwgModel = Ext.create(&#39;Ext.data.Model&#39;, {<br>            fields: [<br>                {name: &#39;mm2&#39;, type: &#39;string&#39;},<br>                {name: &#39;awg&#39;, type: &#39;string&#39;},<br>            ]<br>        });<br><br>        var mm2AwgValues =  new Ext.create(&#39;Ext.data.Store&#39;, {<br>            id: &#39;storeId&#39;,<br>            model: mm2AwgModel,<br>            data : this.data.mm2AwgValues<br>        });<br><br>        var mm2AwgGrid = Ext.create(&#39;Ext.grid.Panel&#39;, {<br>            store: mm2AwgValues,<br>            id: &#39;mm2AwgGrid&#39;,<br>            actions: {<br>                delete:{<br>                    iconCls: &#39;pimcore_icon_delete&#39;,<br>                    tooltip: &quot;Delete&quot;,<br>                    handler: function (obj, row, rowIndex) {<br>                        self.deleteRow(rowIndex);<br>                    }.bind(self, this)<br>                }<br>            },<br>            columns: [<br>                {<br>                    text: &#39;Mm2&#39;,<br>                    dataIndex: &#39;mm2&#39;,<br>                    xtype: &#39;gridcolumn&#39;,<br>                    editor: {<br>                        xtype: &#39;numberfield&#39;<br>                    }<br>                },<br>                {<br>                    text: &#39;Awg&#39;,<br>                    dataIndex: &#39;awg&#39;,<br>                    xtype: &#39;gridcolumn&#39;,<br>                    editor: {<br>                        xtype: &#39;textfield&#39;<br>                    }<br>                },<br>                {<br>                    width: 70,<br>                    sortable: false,<br>                    menuDisabled: true,<br>                    xtype: &#39;actioncolumn&#39;,<br>                    items: [&#39;@delete&#39;]<br>                }<br>            ],<br>            height: 800,<br>            width: 500,<br>            selModel: &#39;cellmodel&#39;,<br>            plugins: {<br>                ptype: &#39;cellediting&#39;,<br>                clicksToEdit: 1<br>            },<br>            renderTo: Ext.getBody()<br>        });<br><br>        var mm2AwgPanel = Ext.create(&#39;Ext.form.Panel&#39;, {<br>            title: t(&#39;MM2-AWG Conversion&#39;),<br>            autoScroll: true,<br>            forceLayout: true,<br>            defaults: {<br>                forceLayout: true,<br>                listeners: {<br>                    render: function (el) {<br>                        me.checkForInheritance(el);<br>                    }<br>                }<br>            },<br>            fieldDefaults: {<br>                labelWidth: 250<br>            },<br>            items: []<br>        });<br><br>        var button = Ext.create(&#39;Ext.Button&#39;, {<br>            text: &#39;Create Row&#39;,<br>            renderTo: Ext.getBody(),<br>            handler: function (obj) {<br>                self.createRow(this);<br>                grid.reconfigure(store) <br>            }.bind(self, this)<br>        });<br><br>        mm2AwgPanel.items.add(mm2AwgGrid);<br>        mm2AwgPanel.items.add(button);<br><br>        this.layout = Ext.create(&#39;Ext.tab.Panel&#39;, {<br>            bodyStyle: &#39;padding:20px 5px 20px 5px;&#39;,<br>            border: true,<br>            autoScroll: true,<br>            forceLayout: true,<br>            defaults: {<br>                forceLayout: true<br>            },<br>            fieldDefaults: {<br>                labelWidth: 500<br>            },<br>            buttons: [<br>                {<br>                    text: t(&#39;save&#39;),<br>                    handler: this.save.bind(this),<br>                    iconCls: &#39;pimcore_icon_apply&#39;<br>                }<br>            ]<br>        });<br><br>        <br>        self.mm2AwgGrid = mm2AwgGrid;<br>        this.layout.add(mm2AwgPanel);<br><br>        this.panel.add(this.layout);<br>        this.layout.setActiveItem(0);<br><br>        pimcore.layout.refresh();<br>    }<br><br>    return this.panel;<br>}</pre><p>Let’s resume the steps made by the function:</p><ul><li>First of all, the menu main panel tab is created.</li><li>Then, the data storage is defined, and a grid is created to show them, adding an extra column to delete a row.</li><li>A sub-panel is created to show the grid; in this way, you can handle multiple sub-tabs in one single menu.</li><li>In the end, all is mixed adding also a button to create a new row.</li></ul><p>In the <a href="https://github.com/MarcoGuiducci/pimcore-Tips-n-Tricks-CustomMenu">article repository</a>, you will also find the specific function to create and delete rows, and the function that calls the controller to save the data, which I can omit in this article as they are not central to the topic.</p><p><strong><em>Last but not least</em></strong>: please note that static JavaScript files are not automatically loaded anymore since the Pimcore X release; to let Pimcore load your scripts, it’s crucial to implement a specific event listener.</p><pre>services:<br>    App\EventListener\PimcoreAdminListener:<br>        tags:<br>            - { name: kernel.event_listener, event: pimcore.bundle_manager.paths.css, method: addCSSFiles }<br>            - { name: kernel.event_listener, event: pimcore.bundle_manager.paths.js, method: addJSFiles }</pre><pre>class PimcoreAdminListener<br>{<br>    public function addJSFiles(PathsEvent $event)<br>    {<br>        $event-&gt;setPaths(<br>            array_merge(<br>                $event-&gt;getPaths(),<br>                [<br>                    &#39;/static/js/startup.js&#39;,<br>                    &#39;/static/js/menu/settings.js&#39;,<br>                ]<br>            )<br>        );<br>    }<br>}</pre><h4>Create the Admin Controller</h4><p>As mentioned in the previous section, we need a controller to retrieve and save the data. The implementation is quite easy, we just need to extend the standard Pimcore AdminAbstractController.</p><pre>/**<br> * @Route(&quot;/admin/custom-menu&quot;)<br> */<br>class CustomMenuController extends AdminAbstractController<br>{<br>    /**<br>     * @Route(&quot;/get-custommenu-settings-attributes&quot;, name=&quot;get-custommenu-settings-attributes&quot;, methods={&quot;GET&quot;})<br>     *<br>     * @return array<br>     */<br>    public function getSettingsAttributesAction(Request $request)<br>    {<br>        $mm2AwgValues = [];<br><br>        $db = Db::get();<br>        $mm2AwgConversionValues = $db-&gt;fetchAllAssociative(&#39;SELECT * FROM mm2_to_awg_conversion&#39;);<br>        foreach ($mm2AwgConversionValues as $value) {<br>            $row = [<br>                &#39;mm2&#39; =&gt; $value[&quot;mm2&quot;],<br>                &#39;awg&#39; =&gt; $value[&quot;awg&quot;],<br>                &#39;id&#39; =&gt; $value[&quot;id&quot;]<br>            ];<br>            <br>            $mm2AwgValues[] = $row;<br>        }<br><br>        $response = [<br>            &quot;mm2AwgValues&quot; =&gt; $mm2AwgValues,<br>        ];<br><br>        return $this-&gt;adminJson([&quot;data&quot; =&gt; $response]);<br>    }<br>    <br>    /**<br>     * @Route(&quot;/save-custommenu-settings-attributes&quot;, methods={&quot;POST&quot;})<br>     */<br>    public function saveSettingsAttributesAction(Request $request)<br>    {<br>        $mm2AwgValues = $request-&gt;get(&quot;mm2AwgValues&quot;);<br>        $mm2AwgSettings = json_decode($mm2AwgValues,true);<br><br>        $response = array(&#39;success&#39; =&gt; true);<br><br>        $db = Db::get();<br><br>        foreach ($mm2AwgSettings as $mm2AwgRow) {<br>            $mm2 = $mm2AwgRow[&quot;mm2&quot;];<br>            $awg = $mm2AwgRow[&quot;awg&quot;];<br>            $id = $mm2AwgRow[&quot;id&quot;];<br><br>            $query = &quot;INSERT INTO mm2_to_awg_conversion (id,mm2, awg) VALUES($id, &#39;$mm2&#39;, &#39;$awg&#39;) ON DUPLICATE KEY UPDATE id=$id, mm2 = &#39;$mm2&#39;, awg = &#39;$awg&#39;&quot;;<br>            $db-&gt;executeQuery($query);<br>        }<br><br>        return $this-&gt;adminJson($response);<br>    }<br>}</pre><h4>A Practical Usage</h4><p>In the article repository, you will find a practical usage of the implemented menu; to be more specific, you will find an example class that has:</p><ul><li>A select attribute served by an OptionProvider for squared millimeters values</li><li>A CalculatedValue attribute that shows the converted AWG value</li></ul><p>You just need to install the repo and discover how all this works.</p><h3>What to Take Home</h3><p>In this article, we have seen how to implement a custom menu in Pimcore. Starting from the migration to add context, we then have seen the steps to render the menu on the frontend and how to serve it through a controller.</p><p>Although this is not a revolutionary implementation, it response to a very real case scenario that developers are facing in their projects.</p><p>Pimcore documentation is great, but it’s often too generic and usually covers only at most 90% of the needs that developers have to face in everyday work; the remaining percentage can be filled only through several hours of reverse engineering and search in community talks (in which, to be honest, it’s hard to find what you need).</p><p>In the next chapter, I will talk about how to automatically render and download a PDF to realize a product technical sheet.</p><p>I hope that sharing knowledge through simple scenarios will help the community grow.</p><h3>References</h3><ul><li><a href="https://pimcore.com/docs/platform/">Pimcore Official Documentation</a></li><li><a href="https://github.com/MarcoGuiducci/pimcore-Tips-n-Tricks-CustomMenu">Source Code for this Article</a></li><li><a href="https://www.amazon.it/Modernizing-Enterprise-CMS-Using-Pimcore/dp/1801075409/">My Published Book about Pimcore</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49052f16239c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>