/**
  * Validate Action
  *
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $response = new \Magento\Framework\DataObject(['error' => false]);
     $variable = $this->_initVariable();
     $variable->addData($this->getRequest()->getPost('variable'));
     $result = $variable->validate();
     if ($result instanceof \Magento\Framework\Phrase) {
         $this->messageManager->addError($result->getText());
         $layout = $this->layoutFactory->create();
         $layout->initMessages();
         $response->setError(true);
         $response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultJsonFactory->create();
     return $resultJson->setData($response->toArray());
 }
Exemple #2
0
 /**
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  * @return string
  */
 public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
 {
     $html = $this->_getHeaderHtml($element);
     $modules = $this->_moduleList->getNames();
     $dispatchResult = new \Magento\Framework\DataObject($modules);
     $this->_eventManager->dispatch('adminhtml_system_config_advanced_disableoutput_render_before', ['modules' => $dispatchResult]);
     $modules = $dispatchResult->toArray();
     sort($modules);
     foreach ($modules as $moduleName) {
         if ($moduleName === 'Magento_Backend') {
             continue;
         }
         $html .= $this->_getFieldHtml($element, $moduleName);
     }
     $html .= $this->_getFooterHtml($element);
     return $html;
 }
 /**
  * @inheritdoc
  */
 public function getCurrency($currency)
 {
     \Magento\Framework\Profiler::start('locale/currency');
     if (!isset(self::$_currencyCache[$this->_localeResolver->getLocale()][$currency])) {
         $options = [];
         try {
             $currencyObject = $this->_currencyFactory->create(['options' => $currency, 'locale' => $this->_localeResolver->getLocale()]);
         } catch (\Exception $e) {
             $currencyObject = $this->_currencyFactory->create(['options' => $this->getDefaultCurrency(), 'locale' => $this->_localeResolver->getLocale()]);
             $options[self::CURRENCY_OPTION_NAME] = $currency;
             $options[self::CURRENCY_OPTION_CURRENCY] = $currency;
             $options[self::CURRENCY_OPTION_SYMBOL] = $currency;
         }
         $options = new \Magento\Framework\DataObject($options);
         $this->_eventManager->dispatch('currency_display_options_forming', ['currency_options' => $options, 'base_code' => $currency]);
         $currencyObject->setFormat($options->toArray());
         self::$_currencyCache[$this->_localeResolver->getLocale()][$currency] = $currencyObject;
     }
     \Magento\Framework\Profiler::stop('locale/currency');
     return self::$_currencyCache[$this->_localeResolver->getLocale()][$currency];
 }