Guest User

Untitled

a guest
Feb 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. namespace VendorNameModuleNameBlockAdminhtmlCustomerEdit;
  2.  
  3. use MagentoCustomerControllerRegistryConstants;
  4. use MagentoUiComponentLayoutTabsTabInterface;
  5. use MagentoBackendBlockWidgetForm;
  6. use MagentoBackendBlockWidgetFormGeneric;
  7. /**
  8. * Customer account form block
  9. */
  10. class Tabs extends Generic implements TabInterface
  11. {
  12. /**
  13. * @var MagentoStoreModelSystemStore
  14. */
  15. protected $_systemStore;
  16. /**
  17. * Core registry
  18. *
  19. * @var MagentoFrameworkRegistry
  20. */
  21. protected $_coreRegistry;
  22.  
  23. /**
  24. * @param MagentoBackendBlockTemplateContext $context
  25. * @param MagentoFrameworkRegistry $registry
  26. * @param array $data
  27. */
  28. public function __construct(
  29. MagentoBackendBlockTemplateContext $context,
  30. MagentoFrameworkRegistry $registry,
  31. MagentoFrameworkDataFormFactory $formFactory,
  32. MagentoStoreModelSystemStore $systemStore,
  33.  
  34. array $data = []
  35. ) {
  36. $this->_coreRegistry = $registry;
  37. $this->_systemStore = $systemStore;
  38. parent::__construct($context, $registry, $formFactory, $data);
  39. }
  40.  
  41. /**
  42. * @return string|null
  43. */
  44. public function getCustomerId()
  45. {
  46. return $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
  47. }
  48.  
  49. /**
  50. * @return MagentoFrameworkPhrase
  51. */
  52. public function getTabLabel()
  53. {
  54. return __('Demo Tab');
  55. }
  56.  
  57. /**
  58. * @return MagentoFrameworkPhrase
  59. */
  60. public function getTabTitle()
  61. {
  62. return __('Demo Tab');
  63. }
  64.  
  65. /**
  66. * @return bool
  67. */
  68. public function canShowTab()
  69. {
  70. if ($this->getCustomerId()) {
  71. return true;
  72. }
  73. return false;
  74. }
  75.  
  76. /**
  77. * @return bool
  78. */
  79. public function isHidden()
  80. {
  81. if ($this->getCustomerId()) {
  82. return false;
  83. }
  84. return true;
  85. }
  86.  
  87. /**
  88. * Tab class getter
  89. *
  90. * @return string
  91. */
  92. public function getTabClass()
  93. {
  94. return '';
  95. }
  96.  
  97. /**
  98. * Return URL link to Tab content
  99. *
  100. * @return string
  101. */
  102. public function getTabUrl()
  103. {
  104. return '';
  105. }
  106.  
  107. /**
  108. * Tab should be loaded trough Ajax call
  109. *
  110. * @return bool
  111. */
  112. public function isAjaxLoaded()
  113. {
  114. return false;
  115. }
  116. public function initForm()
  117. {
  118. if (!$this->canShowTab()) {
  119. return $this;
  120. }
  121. /**@var MagentoFrameworkDataForm $form */
  122. $form = $this->_formFactory->create();
  123. $form->setHtmlIdPrefix('myform_');
  124.  
  125. $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Fields Information')]);
  126.  
  127. $fieldset->addField(
  128. 'demo_field',
  129. 'text',
  130. [
  131. 'name' => 'demo_field',
  132. 'data-form-part' => $this->getData('target_form'),
  133. 'label' => __('Demo Field in Customer Section'),
  134. 'title' => __('Demo Field in Customer Section')
  135. ]
  136. );
  137. $this->setForm($form);
  138. return $this;
  139. }
  140. /**
  141. * @return string
  142. */
  143. protected function _toHtml()
  144. {
  145. if ($this->canShowTab()) {
  146. $this->initForm();
  147. return parent::_toHtml();
  148. } else {
  149. return '';
  150. }
  151. }
  152. }
  153.  
  154. /** @var MagentoFrameworkAppRequestInterface $request */
  155. $request = $this->getRequest();
  156. $originalRequestData = $request->getPostValue();
  157. echo $originalRequestData['demo_field'];
Add Comment
Please, Sign In to add comment