2

I am having custom edit route for core module Magento_Newsletter Subscriber.

When I access Edit route loader keeps spinning and doesn't stop.

In nginx log I got: 2019/02/11 14:55:33 [error] 15820#15820: *5256 access forbidden by rule, client: 127.0.0.1, server: magento2, request: "POST /app/etc/config.php HTTP/1.1", host: "magento2"

Controller in path Pool/Newsletter/Controller/Adminhtml/Subscriber

<?php
namespace Pool\Newsletter\Controller\Adminhtml\Subscriber;

use Magento\Backend\App\Action;
use Magento\Framework\View\Result\PageFactory;

class Edit extends \Magento\Newsletter\Controller\Adminhtml\Subscriber
{

    /**
     */
    protected $_pageFactory;

    /**
     * @var $_registry \Magento\Framework\Registry
     */
    protected $_registry;

    /**
     * Edit constructor.
     * @param Action\Context $context
     * @param PageFactory $resultFactory
     * @param \Magento\Framework\Registry $registry
     * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
     */
    public function __construct(
        Action\Context $context,
        PageFactory $resultFactory,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\Response\Http\FileFactory $fileFactory
    )
    {
        $this->_pageFactory = $resultFactory;
        $this->_registry = $registry;
        parent::__construct($context, $fileFactory);
    }

    public function execute()
    {
        $result = $this->_pageFactory->create();

        $segmentId = $this->getRequest()->getParam('subscriber_id');
        $this->_registry->register('subscriber_id', $segmentId);

        return $result;
    }
}

di in Pool/Module/etc/di.xml

<?xml version="1.0"?>
<!--
/**
* Copyright © 2017 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="DataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Magento\Newsletter\Model\ResourceModel\Subscriber\Collection</argument>
        </arguments>
    </virtualType>

    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="subscriber_listing_data_source" xsi:type="string">Magento\Newsletter\Model\ResourceModel\Subscriber\Collection</item>
            </argument>
        </arguments>
    </type>

<preference for="Magento\Newsletter\Block\Adminhtml\Subscriber\Grid" type="Pool\Newsletter\Block\Adminhtml\Subscriber\Grid"/>
</config>

route in Pool/Module/etc/adminhtml/routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="newsletter" frontName="newsletter">
            <module name="Pool_Newsletter"/>
        </route>
    </router>
</config>

layout

Pool/Newsletter/view/adminhtml/layout/newsletter_subscriber_edit.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <uiComponent name="subscriber_form"/>
        </referenceContainer>
    </body>
</page>

and UI component Pool/Newsletter/view/adminhtml/ui_component/subscriber_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © 2017 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form 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">subscriber_form.subscriber_form_data_source</item>
            <item name="deps" xsi:type="string">subscriber_form.subscriber_form_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">Newsletter Subscriber</item>
        <item name="layout" xsi:type="array">
            <item name="type" xsi:type="string">tabs</item>
            <item name="navContainerName" xsi:type="string">left</item>
        </item>
        <item name="buttons" xsi:type="array">
            <item name="back" xsi:type="string">Pool\Newsletter\Block\Adminhtml\Subscriber\Edit\BackButton
            </item>
            <item name="delete" xsi:type="string">
                Pool\Newsletter\Block\Adminhtml\Subscriber\Edit\DeleteButton
            </item>
            <item name="save" xsi:type="string">Pool\Newsletter\Block\Adminhtml\Subscriber\Edit\SaveButton
            </item>
            <item name="save_and_continue" xsi:type="string">
                Pool\Newsletter\Block\Adminhtml\Subscriber\Edit\SaveAndContinueButton
            </item>
        </item>
    </argument>
    <dataSource name="subscriber_form_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Pool\Newsletter\Ui\Component\Form\Subscriber\DataProvider
            </argument>
            <argument name="name" xsi:type="string">Subscriber_form_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">subscriber_id</argument>
            <argument name="requestFieldName" xsi:type="string">subscriber_id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="submit_url" xsi:type="url" path="*/*/save"/>
                </item>
            </argument>
        </argument>
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
            </item>
        </argument>
    </dataSource>
    <fieldset name="subscriber">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">subscriber</item>
            </item>
        </argument>
        <field name="subscriber_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">subscriber</item>
                </item>
            </argument>
        </field>
        <field name="email">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">subscriber</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>
1
  • <argument name="name" xsi:type="string">Subscriber_form_data_source</argument> uppercase S makes me debug this 5 hours, so it should be subscriber_form_data_source .
    – Newb
    Feb 11, 2019 at 14:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.