2

I tried to add phtml to customer account edit in backend like this:

app/code/Namespace/Module/view/adminhtml/layout/customer_index_edit.xml

<?xml version="1.0"?>

<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">
            <block class="Namespace\Module\Block\Adminhtml\Customer\Edit" name="customer_block_adminhtml_index_edit_custom" cacheable="false" template="Namespace_Module::customer_index_edit.phtml" />
        </referenceContainer>
    </body>
</page>

app/code/Namespace/Module/Block/Adminhtml/Customer/Edit.php

<?php

namespace Namespace\Module\Block\Adminhtml\Customer;

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Controller\RegistryConstants;

class Edit extends \Magento\Backend\Block\Widget\Form\Container
{
    public function __construct(
        \Magento\Backend\Block\Widget\Context $context,
        \Magento\Framework\Registry $registry,
        AccountManagementInterface $customerAccountManagement,
        CustomerRepositoryInterface $customerRepository,
        \Magento\Customer\Helper\View $viewHelper,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;
        $this->customerAccountManagement = $customerAccountManagement;
        $this->customerRepository = $customerRepository;
        $this->_viewHelper = $viewHelper;
        parent::__construct($context, $data);
    }
}

app/code/Namespace/Module/view/adminhtml/templates/customer_index_edit.phtml

<h1> This is new section </h1>

but this is not working at all

0

If you want to add a new tab, it's not too much work.

app/code/Namespace/Module/view/adminhtml/layout/customer_index_edit.xml:

<?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">
    <body>
        <referenceBlock name="customer_form">
            <block class="Namespace\Module\Block\Adminhtml\Customer\View\Custom"
                   name="customer_edit_tab_view_custom"
                   template="Staempfli_Agreements::customer/view/custom.phtml">
            </block>
        </referenceBlock>
    </body>
</page>

app/code/Namespace/Module/Block/Adminhtml/Customer/View/Custom.php

<?php
namespace Namespace\Module\Block\Adminhtml\Customer\View;

class Custom extends \Magento\Customer\Block\Adminhtml\Edit\Tab\View
{
    /**
     * @return \Magento\Framework\Phrase
     */
    public function getTabLabel()
    {
        return __('Custom Label');
    }

    /**
     * @return \Magento\Framework\Phrase
     */
    public function getTabTitle()
    {
        return __('Custom Label');
    }
}

Add your phtml file and that's it.

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.