Form.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\System\Cache;
  7. /**
  8. * Cache management form page
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Form extends \Magento\Backend\Block\Widget\Form\Generic
  13. {
  14. /**
  15. * @var \Magento\Framework\App\Cache\TypeListInterface
  16. */
  17. protected $cacheTypeList;
  18. /**
  19. * @param \Magento\Backend\Block\Template\Context $context
  20. * @param \Magento\Framework\Registry $registry
  21. * @param \Magento\Framework\Data\FormFactory $formFactory
  22. * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  23. * @param array $data
  24. */
  25. public function __construct(
  26. \Magento\Backend\Block\Template\Context $context,
  27. \Magento\Framework\Registry $registry,
  28. \Magento\Framework\Data\FormFactory $formFactory,
  29. \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
  30. array $data = []
  31. ) {
  32. $this->cacheTypeList = $cacheTypeList;
  33. parent::__construct($context, $registry, $formFactory, $data);
  34. }
  35. /**
  36. * Initialize cache management form
  37. *
  38. * @return $this
  39. */
  40. public function initForm()
  41. {
  42. /** @var \Magento\Framework\Data\Form $form */
  43. $form = $this->_formFactory->create();
  44. $fieldset = $form->addFieldset('cache_enable', ['legend' => __('Cache Control')]);
  45. $fieldset->addField(
  46. 'all_cache',
  47. 'select',
  48. [
  49. 'name' => 'all_cache',
  50. 'label' => '<strong>' . __('All Cache') . '</strong>',
  51. 'value' => 1,
  52. 'options' => [
  53. '' => __('No change'),
  54. 'refresh' => __('Refresh'),
  55. 'disable' => __('Disable'),
  56. 'enable' => __('Enable'),
  57. ]
  58. ]
  59. );
  60. foreach ($this->cacheTypeList->getTypeLabels() as $type => $label) {
  61. $fieldset->addField(
  62. 'enable_' . $type,
  63. 'checkbox',
  64. [
  65. 'name' => 'enable[' . $type . ']',
  66. 'label' => __($label),
  67. 'value' => 1,
  68. 'checked' => (int)$this->_cacheState->isEnabled($type)
  69. ]
  70. );
  71. }
  72. $this->setForm($form);
  73. return $this;
  74. }
  75. }