Using Custom Layouts in PimCore to restrict the visibility of editing tabs for selected users or user groups

Anyone who has worked with product data knows that not all parameters assigned to an object should be visible and available for editing to every user. When creating a custom view that includes selected parameters for a given user or user group, an error occurs in PimCore, showing tabs that are not available for those users.

Read below how we fixed it and what caused it.


One of the tools that PimCore offers is the option of defining more than one editing form layout for a data object. This can be done at the PimCore class editor level – by opening the class you want to edit, selecting the Configure Custom Layouts option, and then composing a custom object edit view based on existing data elements.

Custom Layout Definition

This mechanism simply allows you to create views that will later facilitate working on data objects to specific users or user groups. However, there is a use case in which we need to restrict the visibility of selected fields and the option of editing them to selected user groups.

Imagine that we have a product object displayed on a website. This object has basic parameters (such as a name and its translations), technical parameters, financial data and SEO parameters. The latter-most are related to the search engine optimization of the object page and are processed on the object page. Meanwhile, the financial parameters are filled in by accounting and sent to the ERP system, while the technical parameters define the properties of the product itself.

It is immediately clear that not every user of the system should have access to all tabs. For example, accounting staff should not be able to edit SEO and technical parameters, and those responsible for SEO should not be able to change financial parameters. In addition, too many tabs can make it difficult for the system’s users to navigate the editing form.

Thus, let’s create a custom view, showing only the tabs related to the object’s basic parameters and its financial parameters. After this has been created, it still needs to be assigned to a specific group and path: to do this, go to “Users/Groups” / “Groups,” then in the “Areas” tab, enter the path where the products are located and go to “Custom settings” / “Custom layouts” next to the path entered. Here, select the custom view you have created.

From now on, accounting staff will only see the financial and basic parameters of the product they are editing. However, there is a bug in PimCore version 5.8.4 and earlier that causes the product form to load with all tabs after refreshing the browser, including the tabs that should be hidden, if the product was open for editing before the refresh. The error is caused by the fact that the object data request sent by PimCore’s frontend after a page refresh contains an empty layoutId parameter. This makes the system load the default view of the object instead of the view set for the user/user group.

To fix this, just edit line 428 of the class Pimcore\Bundle\AdminBundle\Controller\Admin\DataObject\DataObjectController and replace the existing condition:

if (is_null($currentLayoutId) && !empty($validLayouts))

with:

if ((is_null($currentLayoutId) || !strlen($currentLayoutId)) && !empty($validLayouts))

This will make PimCore properly refresh the custom object view when the page is reloaded.


Our team has already prepared a patch for the core mechanisms in PimCore, which has already been approved. It is available at https://github.com/pimcore/pimcore/pull/4479.

Our Experts
/ Knowledge Shared

19.11.2024

PIM + AI = Success / Optimizing PIM Systems With Artificial Intelligence

Artificial Intelligence

In today’s rapidly changing business world, managing product information has become one of the key challenges, especially for companies operating across multiple markets. Although artificial intelligence is a hot topic, much of the available material focuses mainly on theory or the distant future. We’re taking it a step further – below, we present...

Ilustracja przedstawiająca robota reprezentującego sztuczną inteligencję, otoczonego symbolami wyzwań i błędów w sztucznej inteligencji. Obraz zawiera pomarańczowy mózg, zepsutą żarówkę i cyfrowe piksele, symbolizujące dane i zagrożenia etyczne związane z awariami sztucznej inteligencji
30.10.2024

The Complex World of AI Failures / When Artificial Intelligence Goes Terribly Wrong

Artificial Intelligence

AI has revolutionized industries, offering impressive capabilities in efficiency, speed, and innovation. However, as AI systems become more integrated into business operations, it becomes evident that these tools are not without flaws. From minor glitches to significant ethical issues, AI failures highlight the fragility of these systems. Businesses must...

AI w optymalizacji łańcucha dostaw materiałów budowlanych
28.10.2024

Application of Artificial Intelligence in Optimizing the Supply Chain of Building Materials

Artificial Intelligence

Can artificial intelligence revolutionize the management of building materials supply chains? Learn how AI can help optimize demand forecasting, manage orders and inventory, minimize risks, and personalize customer offerings. Discover the future of AI in the construction industry. The supply chain in the building materials industry is a complex and...

Expert Knowledge
For Your Business

As you can see, we've gained a lot of knowledge over the years - and we love to share! Let's talk about how we can help you.

Contact us

<dialogue.opened>