0

I want to add a tab on User edit page which can be accessed from grid in section System -> All users. I have managed to add tab but it is not loading through AJAX. When I click on tab it redirects to another URL.

Please see screen shot and code below.

enter image description here

Code:-

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

<?php
namespace Namespace\Module\Block\Adminhtml\Edit\Tab;
class Customer extends \Magento\Backend\Block\Widget\Tabs
{
 /**
 * Class constructor
 *
 * @return void
 */
 protected function _construct()
 {
 parent::_construct();
 $this->setId('page_tabs');
 $this->setDestElementId('edit_form');
 }
 /**
 * @return $this
 */
 protected function _beforeToHtml()
 {
 $this->addTab(
 'magcr_customer_section',
 [
 'label' => __('Select Customer(s)'),
 'title' => __('Select Customer(s)'),
 'url' => $this->getUrl('magcr/index/customer'),
 'class' => 'ajax',
 'active' => FALSE
 ]
 );
 return parent::_beforeToHtml();
 }
}

/app/code/Namespace/Module/view/adminhtml/layout/adminhtml_user_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="left">
 <block class="Namespace\Module\Block\Adminhtml\Edit\Tab\Customer" name="adminhtml.user.edit.tabs1"/>
 </referenceContainer>
 </body>
</page>

Please help what am I doing wrong.

UPDATE

When I modify below code in constructor of block class, the tabs loads through ajax.

$this->setId('magcr_page_tabs');

But now problem is both 'User Info' and 'Select Customer(s)' load automatically on page load.

asked Jun 23, 2016 at 6:48

1 Answer 1

0

For example, I add Websites tab

  1. Find current tabs reference "adminhtml.user.edit.tabs" https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/User/view/adminhtml/layout/adminhtml_user_edit.xml#L11

  2. Create your module view xml

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

 <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>
 <referenceBlock name="adminhtml.user.edit.tabs">
 <block class="Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab\Websites" name="tab_websites" template="Magento_Catalog::catalog/product/edit/action/websites.phtml"/>
 <action method="addTab">
 <argument name="name" xsi:type="string">websites</argument>
 <argument name="block" xsi:type="string">tab_websites</argument>
 </action>
 </referenceBlock>
 </body>
 </page>
Rama Chandran M
3,26515 gold badges24 silver badges38 bronze badges
answered May 22, 2018 at 8:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.