ResetButton.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Ui\Component\Design\Config\SearchRobots;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. use Magento\Framework\View\Element\UiComponent\ContextInterface;
  9. use Magento\Framework\View\Element\UiComponentFactory;
  10. use Magento\Ui\Component\Form\Field;
  11. /**
  12. * ResetButton field instance
  13. *
  14. * @api
  15. * @since 100.1.9
  16. */
  17. class ResetButton extends Field
  18. {
  19. /**
  20. * Page robots default instructions
  21. */
  22. const XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS = 'design/search_engine_robots/default_custom_instructions';
  23. /**
  24. * @var ScopeConfigInterface
  25. */
  26. private $scopeConfig;
  27. /**
  28. * ResetButton constructor
  29. *
  30. * @param ContextInterface $context
  31. * @param UiComponentFactory $uiComponentFactory
  32. * @param \Magento\Framework\View\Element\UiComponentInterface[] $components
  33. * @param array $data
  34. * @param ScopeConfigInterface $scopeConfig
  35. */
  36. public function __construct(
  37. ContextInterface $context,
  38. UiComponentFactory $uiComponentFactory,
  39. $components,
  40. array $data,
  41. ScopeConfigInterface $scopeConfig
  42. ) {
  43. $this->scopeConfig = $scopeConfig;
  44. parent::__construct($context, $uiComponentFactory, $components, $data);
  45. }
  46. /**
  47. * Get robots.txt custom instruction default value
  48. *
  49. * @return string
  50. */
  51. private function getRobotsDefaultCustomInstructions()
  52. {
  53. return trim((string)$this->scopeConfig->getValue(
  54. self::XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS,
  55. ScopeConfigInterface::SCOPE_TYPE_DEFAULT
  56. ));
  57. }
  58. /**
  59. * Add js listener to reset button
  60. *
  61. * @return void
  62. * @throws \Magento\Framework\Exception\LocalizedException
  63. * @since 100.1.9
  64. */
  65. public function prepare()
  66. {
  67. parent::prepare();
  68. $this->_data['config']['actions'] = [
  69. [
  70. 'actionName' => 'reset',
  71. 'targetName' => '${ $.name }',
  72. 'params' => [
  73. json_encode($this->getRobotsDefaultCustomInstructions())
  74. ]
  75. ]
  76. ];
  77. }
  78. }