1

I have this xml configuration for index controller.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="content">
        <uiComponent name="cferreboeuf_bienfaiteur_listing"/>
    </referenceContainer>
</page>

The controller's action is defined like that :

<?php
namespace Cferreboeuf\Trainingdb\Controller\Adminhtml\Bienfaiteur;
class Index extends \Magento\Backend\App\Action
{

    const ADMIN_RESOURCE = 'Cferreboeuf_Trainingdb::index';       

    protected $resultPageFactory;
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory)
    {
        $this->resultPageFactory = $resultPageFactory;        
        parent::__construct($context);
    }

    public function execute()
    {
        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
        $resultPage = $this->resultPageFactory->create();
        $resultPage->setActiveMenu('Cferreboeuf_Trainingdb::bienfaiteur');
        $resultPage->addBreadcrumb(__('Training'), __('Training'));
        $resultPage->addBreadcrumb(__('Ajout de bienfaiteurs'), __('Ajout de bienfaiteurs'));
        $resultPage->getConfig()->getTitle()->prepend(__('Bienfaiteurs'));
        return $this->resultPageFactory->create();  
    }
}

The component is a grid that is correct xml.

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">cferreboeuf_bienfaiteur_listing.cferreboeuf_bienfaiteur_data_source</item>
            <item name="deps" xsi:type="string">cferreboeuf_bienfaiteur_listing.cferreboeuf_bienfaiteur_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">cferreboeuf_bienfaiteur_columns</item>
        <item name="buttons" xsi:type="array">
            <item name="add" xsi:type="array">
                <item name="name" xsi:type="string">add</item>
                <item name="label" xsi:type="string" translate="true">Ajouter un bienfaiteur</item>
                <item name="class" xsi:type="string">primary</item>
                <item name="url" xsi:type="string">cferreboeuf_trainingdb/bienfaiteur/new</item>
            </item>
        </item>
    </argument>
    <container name="listing_top">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="template" xsi:type="string">ui/grid/toolbar</item>
            </item>
        </argument>
        <bookmark name="bookmarks">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/controls/bookmarks/bookmarks</item>
                    <item name="displayArea" xsi:type="string">dataGridActions</item>
                    <item name="storageConfig" xsi:type="array">
                        <item name="saveUrl" xsi:type="url" path="mui/bookmark/save"/>
                        <item name="deleteUrl" xsi:type="url" path="mui/bookmark/delete"/>
                        <item name="namespace" xsi:type="string">cferreboeuf_bienfaiteur_listing</item>
                    </item>
                </item>
            </argument>
        </bookmark>
        <container name="columns_controls">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/controls/columns</item>
                    <item name="displayArea" xsi:type="string">dataGridActions</item>
                </item>
            </argument>
        </container>
    </container>
    <dataSource name="cferreboeuf_bienfaiteur_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">BienfaiteurGridDataProvider</argument> <!-- Data provider class -->
            <argument name="name" xsi:type="string">cferreboeuf_bienfaiteur_data_source</argument> <!-- provider defined above -->
            <argument name="primaryFieldName" xsi:type="string">entity_id</argument> <!-- Primary key -->
            <argument name="requestFieldName" xsi:type="string">id</argument> <!-- URL name parameter -->

            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <!-- Primary key column name -->
                        <item name="indexField" xsi:type="string">id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <columns name="cferreboeuf_bienfaiteur_columns">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="editorConfig" xsi:type="array">
                    <item name="selectProvider" xsi:type="string">cferreboeuf_bienfaiteur_listing.cferreboeuf_bienfaiteur_listing.cferreboeuf_bienfaiteur_columns.ids</item>
                    <item name="enabled" xsi:type="boolean">true</item>
                    <item name="indexField" xsi:type="string">entity_id</item>
                    <item name="clientConfig" xsi:type="array">
                        <item name="saveUrl" xsi:type="url" path="cferreboeuf_trainingdb/bienfaiteur/inlineEdit"/>
                        <item name="validateBeforeSave" xsi:type="boolean">false</item>
                    </item>
                </item>
                <item name="childDefaults" xsi:type="array">
                    <item name="fieldAction" xsi:type="array">
                        <item name="provider" xsi:type="string">cferreboeuf_bienfaiteur_listing.cferreboeuf_bienfaiteur_listing.cferreboeuf_bienfaiteur_columns_editor</item>
                        <item name="target" xsi:type="string">startEdit</item>
                        <item name="params" xsi:type="array">
                            <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
                            <item name="1" xsi:type="boolean">true</item>
                        </item>
                    </item>
                </item>
            </item>
        </argument>
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">entity_id</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="entity_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">textRange</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                </item>
            </argument>
        </column>
        <column name="prenom">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="label" xsi:type="string" translate="true">Prénom</item>
                </item>
            </argument>
        </column>
        <column name="nom">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">bienfaiteur</item>
                    <item name="dataScope" xsi:type="string">nom</item>
                    <item name="label" xsi:type="string" translate="true">Nom</item>
                    <item name="filter" xsi:type="string">text</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                    <item name="editor" xsi:type="string">text</item>
                </item>
            </argument>
        </column>
        <column name="ordre">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="editor" xsi:type="array">
                        <item name="editorType" xsi:type="string">text</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>
                        </item>
                    </item>
                    <item name="label" xsi:type="string" translate="true">Ordre de tri</item>
                    <item name="sorting" xsi:type="string">asc</item>
                </item>
            </argument>
        </column>
        <actionsColumn name="actions" class="Cferreboeuf\Trainingdb\Ui\Component\Listing\Column\BienfaiteurActions">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="resizeEnabled" xsi:type="boolean">false</item>
                    <item name="resizeDefaultWidth" xsi:type="string">107</item>
                    <item name="indexField" xsi:type="string">entity_id</item>
                </item>
            </argument>
        </actionsColumn>
    </columns>
</listing>

But when I try to display this list in the admin, I get the error :

Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid UI Component element name: 'cferreboeuf_bienfaiteur_listing'

Where am I incorrect ?

0

The problem comes from the controller. In it, there are two calls to instanciate twice the resultpagefactory. Therefore, the first time the ui component is instanciated and added to the list of uicomponents. The second time, the function prepareData of vendor/magento/module-ui/Model/Manager.php checks for its existence and then says that a uiComponent with this name cannot be created.

/**
 * Prepare the initialization data of UI components
 *
 * @param string $name
 * @return ManagerInterface
 * @throws \Magento\Framework\Exception\LocalizedException
 */
public function prepareData($name)
{
    if ($name === null || $this->hasData($name)) {
        throw new LocalizedException(
            new \Magento\Framework\Phrase("Invalid UI Component element name: '%1'", [$name])
        );
    }
    $this->componentsPool = $this->arrayObjectFactory->create();

    $cacheID = static::CACHE_ID . '_' . $name;
    $cachedPool = $this->cache->load($cacheID);
    if ($cachedPool === false) {
        $this->prepare($name);
        $this->cache->save($this->componentsPool->serialize(), $cacheID);
    } else {
        $this->componentsPool->unserialize($cachedPool);
    }
    $this->componentsData->offsetSet($name, $this->componentsPool);
    $this->componentsData->offsetSet($name, $this->evaluateComponentArguments($this->getData($name)));

    return $this;
}

On line 25 of the controller, it should be return $resultPage;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.