Meta.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © 2015 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Block\Adminhtml\Post\Edit\Tab;
  9. /**
  10. * Admin blog post edit form meta tab
  11. */
  12. class Meta extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
  13. {
  14. /**
  15. * Prepare form
  16. *
  17. * @return $this
  18. */
  19. protected function _prepareForm()
  20. {
  21. /* @var $model \Magefan\Blog\Model\Category */
  22. $model = $this->_coreRegistry->registry('current_model');
  23. /*
  24. * Checking if user have permissions to save information
  25. */
  26. $isElementDisabled = !$this->_isAllowedAction('Magefan_Blog::post');
  27. /** @var \Magento\Framework\Data\Form $form */
  28. $form = $this->_formFactory->create();
  29. $form->setHtmlIdPrefix('post_');
  30. $fieldset = $form->addFieldset(
  31. 'meta_fieldset',
  32. ['legend' => __('Meta Data'), 'class' => 'fieldset-wide']
  33. );
  34. $fieldset->addField(
  35. 'meta_keywords',
  36. 'textarea',
  37. [
  38. 'name' => 'post[meta_keywords]',
  39. 'label' => __('Keywords'),
  40. 'title' => __('Meta Keywords'),
  41. 'disabled' => $isElementDisabled
  42. ]
  43. );
  44. $fieldset->addField(
  45. 'meta_description',
  46. 'textarea',
  47. [
  48. 'name' => 'post[meta_description]',
  49. 'label' => __('Description'),
  50. 'title' => __('Meta Description'),
  51. 'disabled' => $isElementDisabled
  52. ]
  53. );
  54. $this->_eventManager->dispatch('magefan_blog_post_edit_tab_meta_prepare_form', ['form' => $form]);
  55. $form->setValues($model->getData());
  56. $this->setForm($form);
  57. return parent::_prepareForm();
  58. }
  59. /**
  60. * Prepare label for tab
  61. *
  62. * @return \Magento\Framework\Phrase
  63. */
  64. public function getTabLabel()
  65. {
  66. return __('Meta Data');
  67. }
  68. /**
  69. * Prepare title for tab
  70. *
  71. * @return \Magento\Framework\Phrase
  72. */
  73. public function getTabTitle()
  74. {
  75. return __('Meta Data');
  76. }
  77. /**
  78. * Returns status flag about this tab can be shown or not
  79. *
  80. * @return bool
  81. */
  82. public function canShowTab()
  83. {
  84. return true;
  85. }
  86. /**
  87. * Returns status flag about this tab hidden or not
  88. *
  89. * @return bool
  90. */
  91. public function isHidden()
  92. {
  93. return false;
  94. }
  95. /**
  96. * Check permission for passed action
  97. *
  98. * @param string $resourceId
  99. * @return bool
  100. */
  101. protected function _isAllowedAction($resourceId)
  102. {
  103. return $this->_authorization->isAllowed($resourceId);
  104. }
  105. }