/** * @return $this * * @throws \Magento\Framework\Exception\LocalizedException */ public function _prepareForm() { $model = $this->_coreRegistry->registry('current_ddg_rule'); $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Exclusion Rule Conditions')]); $fieldset->addField('combination', 'select', ['label' => __('Conditions Combination Match'), 'title' => __('Conditions Combination Match'), 'name' => 'combination', 'required' => true, 'options' => ['1' => __('ALL'), '2' => __('ANY')], 'after_element_html' => '<small>Choose ANY if using multi line conditions for same attribute. If multi line conditions for same attribute is used and ALL is chosen then multiple lines for same attribute will be ignored.</small>']); $field = $fieldset->addField('condition', 'select', ['name' => 'condition', 'label' => __('Condition'), 'title' => __('Condition'), 'required' => true, 'options' => $this->options->toOptionArray()]); $renderer = $this->getLayout()->createBlock('Dotdigitalgroup\\Email\\Block\\Adminhtml\\Config\\Rules\\Customdatafields'); $field->setRenderer($renderer); $form->setValues($model->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * Execute method. */ public function execute() { $attribute = $this->getRequest()->getParam('attribute'); $conditionName = $this->getRequest()->getParam('condition'); $valueName = $this->getRequest()->getParam('value'); if ($attribute && $conditionName && $valueName) { $type = $this->ruleType->getInputType($attribute); $conditionOptions = $this->ruleCondition->getInputTypeOptions($type); $response['condition'] = $this->_getOptionHtml('conditions', $conditionName, $conditionOptions); $elmType = $this->ruleValue->getValueElementType($attribute); if ($elmType == 'select') { $valueOptions = $this->ruleValue->getValueSelectOptions($attribute); $response['cvalue'] = $this->_getOptionHtml('cvalue', $valueName, $valueOptions); } elseif ($elmType == 'text') { $html = "<input style='width:160px' title='cvalue' class='' id='' name={$valueName} />"; $response['cvalue'] = $html; } $this->http->getHeaders()->clearHeaders(); $this->http->setHeader('Content-Type', 'application/json')->setBody($this->jsonEncoder->encode($response)); } }
/** * Execute method. * * @return $this */ public function execute() { $id = $this->getRequest()->getParam('ruleid'); $attribute = $this->getRequest()->getParam('attribute'); $arrayKey = $this->getRequest()->getParam('arraykey'); $conditionName = $this->getRequest()->getParam('condition'); $valueName = $this->getRequest()->getParam('value'); if ($arrayKey && $id && $attribute && $conditionName && $valueName) { $rule = $this->rulesFactory->create()->load($id); //rule not found if (!$rule->getId()) { $this->http->getHeaders()->clearHeaders(); return $this->http->setHeader('Content-Type', 'application/json')->setBody('Rule not found!'); } $conditions = $rule->getCondition(); $condition = $conditions[$arrayKey]; $selectedConditions = $condition['conditions']; $selectedValues = $condition['cvalue']; $type = $this->ruleType->getInputType($attribute); $conditionOptions = $this->ruleCondition->getInputTypeOptions($type); $response['condition'] = str_replace('value="' . $selectedConditions . '"', 'value="' . $selectedConditions . '"' . 'selected="selected"', $this->getOptionHtml('conditions', $conditionName, $conditionOptions)); $elmType = $this->ruleValue->getValueElementType($attribute); if ($elmType == 'select' or $selectedConditions == 'null') { $isEmpty = false; if ($selectedConditions == 'null') { $isEmpty = true; } $valueOptions = $this->ruleValue->getValueSelectOptions($attribute, $isEmpty); $response['cvalue'] = str_replace('value="' . $selectedValues . '"', 'value="' . $selectedValues . '"' . 'selected="selected"', $this->getOptionHtml('cvalue', $valueName, $valueOptions)); } elseif ($elmType == 'text') { $html = "<input style='width:160px' title='cvalue' name='{$valueName}' value='{$selectedValues}'/>"; $response['cvalue'] = $html; } $this->http->getHeaders()->clearHeaders(); $this->http->setHeader('Content-Type', 'application/json')->setBody($this->jsonEncoder->encode($response)); } }