Magento 2 :- How can i add tab in customer group?

by Kushal   Last Updated January 12, 2018 11:09 AM

I tried to create new tabs as per the customer tab, add in admin side, but I am getting the error so can any one help me. How can i do this thing?

I refer this link for that
1) http://www.dckap.com/blog/tab-in-customer-admin-in-magento-2/

2) http://www.ibnab.com/en/blog/magento-2/magento-2-backend-create-custom-tab-in-customer-view-and-load-grid-inside-admin enter image description here

For testing purpose i tried in vendor for now
vendor/magento/module-customer/Block/Adminhtml/Group/Edit/Tabs.php

<?php
// namespace Ced\Mymodule\Block\Adminhtml\Custom\Edit;
namespace Magento\Customer\Block\Adminhtml\Group\Edit;

class Tabs extends \Magento\Backend\Block\Widget\Tabs
{
   protected function _construct()
   {

       parent::_construct();
       $this->setId('checkmodule_custom_tabs');
       $this->setDestElementId('edit_form');
       $this->setTitle(__('Custom Information'));
   }
}

vendor/magento/module-customer/Block/Adminhtml/Group/Edit/Tab/Tab1.php

<?php
//namespace Ced\Mymodule\Block\Adminhtml\Custom\Edit\Tab;
namespace Magento\Customer\Block\Adminhtml\Group\Edit\Tab;
class Tab1 extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
   /**
    * @var \Magento\Store\Model\System\Store
    */
   protected $_systemStore;

   /**
    * @param \Magento\Backend\Block\Template\Context $context
    * @param \Magento\Framework\Registry $registry
    * @param \Magento\Framework\Data\FormFactory $formFactory
    * @param \Magento\Store\Model\System\Store $systemStore
    * @param array $data
    */
   public function __construct(
       \Magento\Backend\Block\Template\Context $context,
       \Magento\Framework\Registry $registry,
       \Magento\Framework\Data\FormFactory $formFactory,
       \Magento\Store\Model\System\Store $systemStore,
       array $data = array()
   ) {
       $this->_systemStore = $systemStore;
       parent::__construct($context, $registry, $formFactory, $data);
   }

   /**
    * Prepare form
    *
    * @return $this
    */
   protected function _prepareForm()
   {
/* @var $model \Magento\Cms\Model\Page */
       $model = $this->_coreRegistry->registry('mymodule_custom');
$isElementDisabled = false;
       /** @var \Magento\Framework\Data\Form $form */
       $form = $this->_formFactory->create();

       $form->setHtmlIdPrefix('page_');

       $fieldset = $form->addFieldset('base_fieldset', array('legend' => __('Tab1')));

       if ($model->getId()) {
           $fieldset->addField('id', 'hidden', array('name' => 'id'));
       }

$fieldset->addField(
           'col1',
           'text',
           array(
               'name' => 'col1',
               'label' => __('label1'),
               'title' => __('label1'),
               /*'required' => true,*/
           )
       );
/*{{CedAddFormField}}*/

       if (!$model->getId()) {
           $model->setData('status', $isElementDisabled ? '2' : '1');
       }

       $form->setValues($model->getData());
       $this->setForm($form);

       return parent::_prepareForm();   
   }

   /**
    * Prepare label for tab
    *
    * @return string
    */
   public function getTabLabel()
   {
       return __('Tab1');
   }

   /**
    * Prepare title for tab
    *
    * @return string
    */
   public function getTabTitle()
   {
       return __('Tab1');
   }

   /**
    * {@inheritdoc}
    */
   public function canShowTab()
   {
       return true;
   }

   /**
    * {@inheritdoc}
    */
   public function isHidden()
   {
       return false;
   }

    /**
    * Check permission for passed action
    *
    * @param string $resourceId
    * @return bool
    */
   protected function _isAllowedAction($resourceId)
   {
       return $this->_authorization->isAllowed($resourceId);
   }
}

vendor/magento/module-customer/view/adminhtml/layout/customer_group_index.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="Magento\Customer\Block\Adminhtml\Group\Edit" name="mymodule_custom_edit"/>
            <block class="Magento\Customer\Block\Adminhtml\Group" name="adminhtml.block.customer.group.grid.container">
                <block class="Magento\Backend\Block\Widget\Grid" name="adminhtml.block.customer.group.grid" as="grid">
                    <arguments>
                        <argument name="id" xsi:type="string">customerGroupGrid</argument>
                        <argument name="dataSource" xsi:type="object">Magento\Customer\Model\ResourceModel\Group\Grid\ServiceCollection</argument>
                        <argument name="default_sort" xsi:type="string">type</argument>
                        <argument name="default_dir" xsi:type="string">asc</argument>
                        <argument name="save_parameters_in_session" xsi:type="string">1</argument>
                    </arguments>
                    <block class="Magento\Backend\Block\Widget\Grid\ColumnSet" as="grid.columnSet" name="adminhtml.customer.group.grid.columnSet">
                        <arguments>
                            <argument name="rowUrl" xsi:type="array">
                                <item name="path" xsi:type="string">customer/*/edit</item>
                                <item name="extraParamsTemplate" xsi:type="array">
                                    <item name="id" xsi:type="string">getId</item>
                                </item>
                            </argument>
                        </arguments>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="time">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">ID</argument>
                                <argument name="id" xsi:type="string">id</argument>
                                <argument name="index" xsi:type="string">id</argument>
                                <argument name="column_css_class" xsi:type="string">col-id</argument>
                                <argument name="header_css_class" xsi:type="string">col-id</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="type">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Group</argument>
                                <argument name="index" xsi:type="string">code</argument>
                            </arguments>
                        </block>
                        <block class="Magento\Backend\Block\Widget\Grid\Column" as="class_name">
                            <arguments>
                                <argument name="header" xsi:type="string" translate="true">Tax Class</argument>
                                <argument name="index" xsi:type="string">tax_class_name</argument>
                            </arguments>
                        </block>
                    </block>
                </block>
            </block>
        </referenceContainer>
        <referenceContainer name="left">
            <block class="Magento\Customer\Block\Adminhtml\Group\Edit\Tabs" name="mymodule_custom_edit_tabs">
                <block class="Magento\Customer\Block\Adminhtml\Group\Edit\Tab\Tab1" name="mymodule_custom_edit_tab_tab1"/>
                 <action method="addTab">
                    <argument name="name" xsi:type="string">tab1_section</argument>
                    <argument name="block" xsi:type="string">mymodule_custom_edit_tab_tab1</argument>
                </action>
        </referenceContainer>
    </body>
</page>


Related Questions