PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php

https://github.com/jonathanselander/magento2
PHP | 124 lines | 43 code | 10 blank | 71 comment | 0 complexity | e68846d27dc617fa7d4235a0cf07ddda MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Unlicense
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Magento
  22. * @package Magento_Backend
  23. * @copyright Copyright (c) 2013 X.commerce, Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * "Reset to Defaults" button renderer
  28. *
  29. * @category Magento
  30. * @package Magento_Backend
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. namespace Magento\Backend\Block\Page\System\Config\Robots;
  34. class Reset extends \Magento\Backend\Block\System\Config\Form\Field
  35. {
  36. /**
  37. * Pasge robots default instructions
  38. */
  39. const XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS = 'design/search_engine_robots/default_custom_instructions';
  40. /**
  41. * Page robots
  42. *
  43. * @var \Magento\Theme\Helper\Robots
  44. */
  45. protected $coreConfig;
  46. /**
  47. * @param \Magento\Backend\Block\Template\Context $context
  48. * @param \Magento\Core\Model\ConfigInterface $coreConfig
  49. * @param array $data
  50. */
  51. public function __construct(
  52. \Magento\Backend\Block\Template\Context $context,
  53. \Magento\Core\Model\ConfigInterface $coreConfig,
  54. array $data = array()
  55. ) {
  56. $this->coreConfig = $coreConfig;
  57. parent::__construct($context, $data);
  58. }
  59. /*
  60. * Set template
  61. */
  62. protected function _construct()
  63. {
  64. parent::_construct();
  65. $this->setTemplate('page/system/config/robots/reset.phtml');
  66. }
  67. /**
  68. * Get robots.txt custom instruction default value
  69. *
  70. * @return string
  71. */
  72. public function getRobotsDefaultCustomInstructions()
  73. {
  74. return trim((string)$this->coreConfig->getValue(self::XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS, 'default'));
  75. }
  76. /**
  77. * Generate button html
  78. *
  79. * @return string
  80. */
  81. public function getButtonHtml()
  82. {
  83. $button = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')
  84. ->setData(array(
  85. 'id' => 'reset_to_default_button',
  86. 'label' => __('Reset to Default'),
  87. 'onclick' => 'javascript:resetRobotsToDefault(); return false;'
  88. ));
  89. return $button->toHtml();
  90. }
  91. /**
  92. * Render button
  93. *
  94. * @param \Magento\Data\Form\Element\AbstractElement $element
  95. * @return string
  96. */
  97. public function render(\Magento\Data\Form\Element\AbstractElement $element)
  98. {
  99. // Remove scope label
  100. $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
  101. return parent::render($element);
  102. }
  103. /**
  104. * Return element html
  105. *
  106. * @param \Magento\Data\Form\Element\AbstractElement $element
  107. * @return string
  108. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  109. */
  110. protected function _getElementHtml(\Magento\Data\Form\Element\AbstractElement $element)
  111. {
  112. return $this->_toHtml();
  113. }
  114. }