Conditions.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace Dotdigitalgroup\Email\Block\Adminhtml\Rules\Edit\Tab;
  3. /**
  4. * Exclusion rules conditions tab block
  5. *
  6. * @api
  7. */
  8. class Conditions extends \Magento\Backend\Block\Widget\Form\Generic implements
  9. \Magento\Backend\Block\Widget\Tab\TabInterface
  10. {
  11. /**
  12. * @var \Dotdigitalgroup\Email\Model\Adminhtml\Source\Rules\Type
  13. */
  14. public $options;
  15. /**
  16. * Conditions constructor.
  17. *
  18. * @param \Magento\Backend\Block\Widget\Context $context
  19. * @param \Magento\Framework\Registry $registry
  20. * @param \Magento\Framework\Data\FormFactory $formFactory
  21. * @param \Dotdigitalgroup\Email\Model\Adminhtml\Source\Rules\Type $options
  22. * @param array $data
  23. */
  24. public function __construct(
  25. \Magento\Backend\Block\Widget\Context $context,
  26. \Magento\Framework\Registry $registry,
  27. \Magento\Framework\Data\FormFactory $formFactory,
  28. \Dotdigitalgroup\Email\Model\Adminhtml\Source\Rules\Type $options,
  29. array $data = []
  30. ) {
  31. $this->options = $options;
  32. parent::__construct($context, $registry, $formFactory, $data);
  33. }
  34. /**
  35. * Prepare content for tab.
  36. *
  37. * @return string
  38. */
  39. public function getTabLabel()
  40. {
  41. return __('Conditions');
  42. }
  43. /**
  44. * Prepare title for tab.
  45. *
  46. * @return string
  47. */
  48. public function getTabTitle()
  49. {
  50. return __('Conditions');
  51. }
  52. /**
  53. * Returns status flag about this tab can be showen or not.
  54. *
  55. * @return true
  56. */
  57. public function canShowTab()
  58. {
  59. return true;
  60. }
  61. /**
  62. * Returns status flag about this tab hidden or not.
  63. *
  64. * @return true
  65. */
  66. public function isHidden()
  67. {
  68. return false;
  69. }
  70. /**
  71. * @return \Magento\Backend\Block\Widget\Form\Generic
  72. *
  73. * @throws \Magento\Framework\Exception\LocalizedException
  74. */
  75. public function _prepareForm()
  76. {
  77. $model = $this->_coreRegistry->registry('current_ddg_rule');
  78. $form = $this->_formFactory->create();
  79. $form->setHtmlIdPrefix('rule_');
  80. $fieldset = $form->addFieldset(
  81. 'base_fieldset',
  82. ['legend' => __('Exclusion Rule Conditions')]
  83. );
  84. $fieldset->addField('combination', 'select', [
  85. 'label' => __('Conditions Combination Match'),
  86. 'title' => __('Conditions Combination Match'),
  87. 'name' => 'combination',
  88. 'required' => true,
  89. 'options' => [
  90. '1' => __('ALL'),
  91. '2' => __('ANY'),
  92. ],
  93. 'after_element_html' => '<small>Choose ANY if using multi line conditions
  94. for same attribute. If multi line conditions for same attribute is used and ALL is chosen
  95. then multiple lines for same attribute will be ignored.</small>',
  96. ]);
  97. $field = $fieldset->addField('condition', 'select', [
  98. 'name' => 'condition',
  99. 'label' => __('Condition'),
  100. 'title' => __('Condition'),
  101. 'required' => true,
  102. 'options' => $this->options->toOptionArray(),
  103. ]);
  104. $renderer = $this->getLayout()
  105. ->createBlock(\Dotdigitalgroup\Email\Block\Adminhtml\Config\Rules\Customdatafields::class);
  106. $field->setRenderer($renderer);
  107. $form->setValues($model->getData());
  108. $this->setForm($form);
  109. return parent::_prepareForm();
  110. }
  111. }