Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace VendorNameModuleNameBlockAdminhtmlCustomerEdit;
- use MagentoCustomerControllerRegistryConstants;
- use MagentoUiComponentLayoutTabsTabInterface;
- use MagentoBackendBlockWidgetForm;
- use MagentoBackendBlockWidgetFormGeneric;
- /**
- * Customer account form block
- */
- class Tabs extends Generic implements TabInterface
- {
- /**
- * @var MagentoStoreModelSystemStore
- */
- protected $_systemStore;
- /**
- * Core registry
- *
- * @var MagentoFrameworkRegistry
- */
- protected $_coreRegistry;
- /**
- * @param MagentoBackendBlockTemplateContext $context
- * @param MagentoFrameworkRegistry $registry
- * @param array $data
- */
- public function __construct(
- MagentoBackendBlockTemplateContext $context,
- MagentoFrameworkRegistry $registry,
- MagentoFrameworkDataFormFactory $formFactory,
- MagentoStoreModelSystemStore $systemStore,
- array $data = []
- ) {
- $this->_coreRegistry = $registry;
- $this->_systemStore = $systemStore;
- parent::__construct($context, $registry, $formFactory, $data);
- }
- /**
- * @return string|null
- */
- public function getCustomerId()
- {
- return $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
- }
- /**
- * @return MagentoFrameworkPhrase
- */
- public function getTabLabel()
- {
- return __('Demo Tab');
- }
- /**
- * @return MagentoFrameworkPhrase
- */
- public function getTabTitle()
- {
- return __('Demo Tab');
- }
- /**
- * @return bool
- */
- public function canShowTab()
- {
- if ($this->getCustomerId()) {
- return true;
- }
- return false;
- }
- /**
- * @return bool
- */
- public function isHidden()
- {
- if ($this->getCustomerId()) {
- return false;
- }
- return true;
- }
- /**
- * Tab class getter
- *
- * @return string
- */
- public function getTabClass()
- {
- return '';
- }
- /**
- * Return URL link to Tab content
- *
- * @return string
- */
- public function getTabUrl()
- {
- return '';
- }
- /**
- * Tab should be loaded trough Ajax call
- *
- * @return bool
- */
- public function isAjaxLoaded()
- {
- return false;
- }
- public function initForm()
- {
- if (!$this->canShowTab()) {
- return $this;
- }
- /**@var MagentoFrameworkDataForm $form */
- $form = $this->_formFactory->create();
- $form->setHtmlIdPrefix('myform_');
- $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Fields Information')]);
- $fieldset->addField(
- 'demo_field',
- 'text',
- [
- 'name' => 'demo_field',
- 'data-form-part' => $this->getData('target_form'),
- 'label' => __('Demo Field in Customer Section'),
- 'title' => __('Demo Field in Customer Section')
- ]
- );
- $this->setForm($form);
- return $this;
- }
- /**
- * @return string
- */
- protected function _toHtml()
- {
- if ($this->canShowTab()) {
- $this->initForm();
- return parent::_toHtml();
- } else {
- return '';
- }
- }
- }
- /** @var MagentoFrameworkAppRequestInterface $request */
- $request = $this->getRequest();
- $originalRequestData = $request->getPostValue();
- echo $originalRequestData['demo_field'];
Add Comment
Please, Sign In to add comment