Reset.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\Page\System\Config\Robots;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. /**
  9. * "Reset to Defaults" button renderer
  10. *
  11. * @deprecated 100.1.6
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. */
  14. class Reset extends \Magento\Config\Block\System\Config\Form\Field
  15. {
  16. /**
  17. * Pasge robots default instructions
  18. */
  19. const XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS = 'design/search_engine_robots/default_custom_instructions';
  20. /**
  21. * @param \Magento\Backend\Block\Template\Context $context
  22. * @param array $data
  23. */
  24. public function __construct(
  25. \Magento\Backend\Block\Template\Context $context,
  26. array $data = []
  27. ) {
  28. parent::__construct($context, $data);
  29. }
  30. /**
  31. * Set template
  32. *
  33. * @return void
  34. */
  35. protected function _construct()
  36. {
  37. parent::_construct();
  38. $this->setTemplate('Magento_Config::page/system/config/robots/reset.phtml');
  39. }
  40. /**
  41. * Get robots.txt custom instruction default value
  42. *
  43. * @return string
  44. */
  45. public function getRobotsDefaultCustomInstructions()
  46. {
  47. return trim((string)$this->_scopeConfig->getValue(
  48. self::XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS,
  49. ScopeConfigInterface::SCOPE_TYPE_DEFAULT
  50. ));
  51. }
  52. /**
  53. * Generate button html
  54. *
  55. * @return string
  56. */
  57. public function getButtonHtml()
  58. {
  59. $button = $this->getLayout()->createBlock(
  60. \Magento\Backend\Block\Widget\Button::class
  61. )->setData(
  62. [
  63. 'id' => 'reset_to_default_button',
  64. 'label' => __('Reset to Default'),
  65. 'onclick' => 'javascript:resetRobotsToDefault(); return false;',
  66. ]
  67. );
  68. return $button->toHtml();
  69. }
  70. /**
  71. * Render button
  72. *
  73. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  74. * @return string
  75. */
  76. public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  77. {
  78. // Remove scope label
  79. $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
  80. return parent::render($element);
  81. }
  82. /**
  83. * Return element html
  84. *
  85. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  86. * @return string
  87. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  88. */
  89. protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  90. {
  91. return $this->_toHtml();
  92. }
  93. }