Beispiel #1
25
 /**
  * @param AbstractElement $element
  * @return string
  */
 public function render(AbstractElement $element)
 {
     $html = $this->_getHeaderHtml($element);
     foreach ($this->_imageTypes as $key => $attribute) {
         /**
          * Watermark size field
          */
         /** @var \Magento\Framework\Data\Form\Element\Text $field */
         $field = $this->_elementFactory->create('text');
         $field->setName("groups[watermark][fields][{$key}_size][value]")->setForm($this->getForm())->setLabel(__('Size for %1', $attribute['title']))->setRenderer($this->_formField);
         $html .= $field->toHtml();
         /**
          * Watermark upload field
          */
         /** @var \Magento\Framework\Data\Form\Element\Imagefile $field */
         $field = $this->_elementFactory->create('imagefile');
         $field->setName("groups[watermark][fields][{$key}_image][value]")->setForm($this->getForm())->setLabel(__('Watermark File for %1', $attribute['title']))->setRenderer($this->_formField);
         $html .= $field->toHtml();
         /**
          * Watermark position field
          */
         /** @var \Magento\Framework\Data\Form\Element\Select $field */
         $field = $this->_elementFactory->create('select');
         $field->setName("groups[watermark][fields][{$key}_position][value]")->setForm($this->getForm())->setLabel(__('Position of Watermark for %1', $attribute['title']))->setRenderer($this->_formField)->setValues($this->_watermarkPosition->toOptionArray());
         $html .= $field->toHtml();
     }
     $html .= $this->_getFooterHtml($element);
     return $html;
 }
 public function renderCellTemplate($columnName)
 {
     $options = [];
     if ($columnName == 'currencyCode' && isset($this->_columns[$columnName])) {
         $optionsCurency = $this->_objectManager->get('Magento\\Directory\\Model\\Currency')->getConfigAllowCurrencies();
         foreach ($optionsCurency as $code => $currency) {
             $options[] = ['value' => $currency, 'label' => $currency];
         }
     } else {
         if ($columnName == 'store' && isset($this->_columns[$columnName])) {
             $options = $this->_systemStore->getStoreValuesForForm(false, false);
         } else {
             if ($columnName == 'countryCode' && isset($this->_columns[$columnName])) {
                 $optionsCurency = $this->_geoipHelper->getCountryList();
                 foreach ($optionsCurency as $code => $country) {
                     $options[] = ['value' => $code, 'label' => $country];
                 }
                 /*$options = $this->_objectManager->get('Magento\Directory\Model\Config\Source\Country')->toOptionArray();
                   array_shift($options);*/
             }
         }
     }
     if (count($options) > 0) {
         $element = $this->_elementFactory->create('select');
         $element->setForm($this->getForm())->setName($this->_getCellInputElementName($columnName))->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName))->setValues($options);
         return str_replace("\n", '', $element->getElementHtml());
     }
     return parent::renderCellTemplate($columnName);
 }
Beispiel #3
0
 /**
  * Checkbox render function
  *
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  * @return string
  */
 public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
 {
     /** @var \Magento\Framework\Data\Form\Element\Checkbox $checkbox */
     $checkbox = $this->_elementFactory->create('checkbox', array('data' => $element->getData()));
     $checkbox->setForm($element->getForm());
     $elementHtml = sprintf('<div class="field no-label field-%s with-note">' . '<div class="control">' . '<div class="nested">' . '<div class="field choice"> %s' . '<label class="label" for="%s">%s</label>' . '<p class="note">%s</p>' . '</div>' . '</div>' . '</div>' . '</div>', $element->getHtmlId(), $checkbox->getElementHtml(), $element->getHtmlId(), $element->getLabel(), $element->getNote());
     return $elementHtml;
 }
Beispiel #4
0
 /**
  * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
  * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
  * @param \Magento\Framework\Escaper $escaper
  * @param \Magento\Catalog\Helper\Product $helper
  * @param array $data
  */
 public function __construct(\Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, \Magento\Framework\Escaper $escaper, \Magento\Catalog\Helper\Product $helper, array $data = [])
 {
     $this->_helper = $helper;
     $this->_virtual = $factoryElement->create('checkbox');
     $this->_virtual->setId(self::VIRTUAL_FIELD_HTML_ID)->setName('is_virtual')->setLabel($this->_helper->getTypeSwitcherControlLabel());
     $data['class'] = 'validate-number validate-zero-or-greater validate-number-range number-range-0-99999999.9999';
     parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
 }
Beispiel #5
0
 /**
  * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
  * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
  * @param \Magento\Framework\Escaper $escaper
  * @param \Magento\Framework\Locale\Format $localeFormat
  * @param \Magento\Directory\Helper\Data $directoryHelper
  * @param array $data
  */
 public function __construct(\Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, \Magento\Framework\Escaper $escaper, \Magento\Framework\Locale\Format $localeFormat, \Magento\Directory\Helper\Data $directoryHelper, array $data = [])
 {
     $this->directoryHelper = $directoryHelper;
     $this->localeFormat = $localeFormat;
     $this->weightSwitcher = $factoryElement->create('radios');
     $this->weightSwitcher->setValue(WeightResolver::HAS_WEIGHT)->setValues([['value' => WeightResolver::HAS_WEIGHT, 'label' => __('Yes')], ['value' => WeightResolver::HAS_NO_WEIGHT, 'label' => __('No')]])->setId('weight-switcher')->setName('product_has_weight')->setLabel(__('Does this have a weight?'));
     parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
     $this->addClass('validate-zero-or-greater');
 }
 /**
  * Render array cell for prototypeJS template
  *
  * @param string $columnName
  * @return string
  */
 public function renderCellTemplate($columnName)
 {
     if ($columnName == 'value' && isset($this->_columns[$columnName])) {
         /** @var $label \Magento\Framework\View\Design\Theme\Label */
         $label = $this->_labelFactory->create();
         $options = $label->getLabelsCollection(__('-- No Theme --'));
         $element = $this->_elementFactory->create('select');
         $element->setForm($this->getForm())->setName($this->_getCellInputElementName($columnName))->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName))->setValues($options);
         return str_replace("\n", '', $element->getElementHtml());
     }
     return parent::renderCellTemplate($columnName);
 }
 /**
  * Render array cell for JS template
  *
  * @param string $columnName The column name
  *
  * @return string
  */
 public function renderCellTemplate($columnName)
 {
     if ($columnName == 'term_id' && isset($this->_columns[$columnName])) {
         $element = $this->elementFactory->create('hidden');
         $element->setId("term_id")->setName("term_id");
         $element->setForm($this->getForm())->setName($this->_getCellInputElementName($columnName))->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName));
         return $element->getElementHtml();
     }
     if ($columnName == 'values' && isset($this->_columns[$columnName])) {
         $element = $this->elementFactory->create('textarea');
         $element->setCols($this->textAreaColsNumber)->setForm($this->getForm())->setName($this->_getCellInputElementName($columnName))->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName));
         return str_replace("\n", '', $element->getElementHtml());
     }
     return parent::renderCellTemplate($columnName);
 }
 /**
  * Add column element
  *
  * @param string $elementId
  * @param array $config
  * @return Column
  */
 public function addColumn($elementId, $config)
 {
     $element = $this->_factoryElement->create('column', ['data' => $config]);
     $element->setForm($this)->setId($elementId);
     $this->addElement($element);
     return $element;
 }
 /**
  * @param string $columnName
  *
  * @return mixed|string
  */
 public function renderCellTemplate($columnName)
 {
     if ($columnName == 'attribute' && isset($this->_columns[$columnName])) {
         $options = $this->getElement()->getValues();
         $element = $this->elementFactory->create('select');
         $element->setForm($this->getForm())->setName($this->_getCellInputElementName($columnName))->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName))->setValues($options);
         return str_replace("\n", '', $element->getElementHtml());
     }
     if ($columnName == 'datafield' && isset($this->_columns[$columnName])) {
         $options = $this->datafieldsFactory->toOptionArray();
         $element = $this->elementFactory->create('select');
         $element->setForm($this->getForm())->setName($this->_getCellInputElementName($columnName))->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName))->setValues($options);
         return str_replace("\n", '', $element->getElementHtml());
     }
     return parent::renderCellTemplate($columnName);
 }
Beispiel #10
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     $standard = $this->_paypalStandardFactory->create();
     $form = $this->_formFactory->create();
     $form->setAction($standard->getConfig()->getPaypalUrl())->setId('paypal_standard_checkout')->setName('paypal_standard_checkout')->setMethod('POST')->setUseContainer(true);
     foreach ($standard->getStandardCheckoutFormFields() as $field => $value) {
         $form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
     }
     $idSuffix = $this->mathRandom->getUniqueHash();
     $submitButton = $this->_elementFactory->create('submit', array('data' => array('value' => __('Click here if you are not redirected within 10 seconds.'))));
     $id = "submit_to_paypal_button_{$idSuffix}";
     $submitButton->setId($id);
     $form->addElement($submitButton);
     $html = '<html><body>';
     $html .= __('You will be redirected to the PayPal website in a few seconds.');
     $html .= $form->toHtml();
     $html .= '<script type="text/javascript">document.getElementById("paypal_standard_checkout").submit();';
     $html .= '</script></body></html>';
     return $html;
 }
Beispiel #11
0
    /**
     * Return chooser HTML and init scripts
     *
     * @return string
     */
    protected function _toHtml()
    {
        $element = $this->getElement();
        /* @var $fieldset \Magento\Framework\Data\Form\Element\Fieldset */
        $fieldset = $element->getForm()->getElement($this->getFieldsetId());
        $chooserId = $this->getUniqId();
        $config = $this->getConfig();
        // add chooser element to fieldset
        $chooser = $fieldset->addField('chooser' . $element->getId(), 'note', ['label' => $config->getLabel() ? $config->getLabel() : '', 'value_class' => 'value2']);
        $hiddenHtml = '';
        if ($this->getHiddenEnabled()) {
            $hidden = $this->_elementFactory->create('hidden', ['data' => $element->getData()]);
            $hidden->setId("{$chooserId}value")->setForm($element->getForm());
            if ($element->getRequired()) {
                $hidden->addClass('required-entry');
            }
            $hiddenHtml = $hidden->getElementHtml();
            $element->setValue('');
        }
        $buttons = $config->getButtons();
        $chooseButton = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Button')->setType('button')->setId($chooserId . 'control')->setClass('btn-chooser')->setLabel($buttons['open'])->setOnclick($chooserId . '.choose()')->setDisabled($element->getReadonly());
        $chooser->setData('after_element_html', $hiddenHtml . $chooseButton->toHtml());
        // render label and chooser scripts
        $configJson = $this->_jsonEncoder->encode($config->getData());
        return '
            <label class="widget-option-label" id="' . $chooserId . 'label">' . ($this->getLabel() ? $this->getLabel() : __('Not Selected')) . '</label>
            <div id="' . $chooserId . 'advice-container" class="hidden"></div>
            <script>
            require(["prototype", "mage/adminhtml/wysiwyg/widget"], function(){
            //<![CDATA[
                (function() {
                    var instantiateChooser = function() {
                        window.' . $chooserId . ' = new WysiwygWidget.chooser(
                            "' . $chooserId . '",
                            "' . $this->getSourceUrl() . '",
                            ' . $configJson . '
                        );
                        if ($("' . $chooserId . 'value")) {
                            $("' . $chooserId . 'value").advaiceContainer = "' . $chooserId . 'advice-container";
                        }
                    }

                    if (document.loaded) { //allow load over ajax
                        instantiateChooser();
                    } else {
                        document.observe("dom:loaded", instantiateChooser);
                    }
                })();
            //]]>
            });
            </script>
        ';
    }
Beispiel #12
0
 /**
  * @return string
  */
 public function getElementHtml()
 {
     /** @var \Magento\Framework\Data\Form\Element\AbstractElement $element */
     $element = $this->getElement();
     if (!$element->getValue()) {
         return parent::getElementHtml();
     }
     $element->setOnkeyup("onUrlkeyChanged('" . $element->getHtmlId() . "')");
     $element->setOnchange("onUrlkeyChanged('" . $element->getHtmlId() . "')");
     $data = array('name' => $element->getData('name') . '_create_redirect', 'disabled' => true);
     /** @var \Magento\Framework\Data\Form\Element\Hidden $hidden */
     $hidden = $this->_elementFactory->create('hidden', array('data' => $data));
     $hidden->setForm($element->getForm());
     $storeId = $element->getForm()->getDataObject()->getStoreId();
     $data['html_id'] = $element->getHtmlId() . '_create_redirect';
     $data['label'] = __('Create Permanent Redirect for old URL');
     $data['value'] = $element->getValue();
     $data['checked'] = $this->_catalogData->shouldSaveUrlRewritesHistory($storeId);
     /** @var \Magento\Framework\Data\Form\Element\Checkbox $checkbox */
     $checkbox = $this->_elementFactory->create('checkbox', array('data' => $data));
     $checkbox->setForm($element->getForm());
     return parent::getElementHtml() . '<br/>' . $hidden->getElementHtml() . $checkbox->getElementHtml() . $checkbox->getLabelHtml();
 }
 /**
  * @return string
  */
 public function getElementHtml()
 {
     /** @var \Magento\Framework\Data\Form\Element\AbstractElement $element */
     $element = $this->getElement();
     if (!$element->getValue()) {
         return parent::getElementHtml();
     }
     $element->setOnkeyup("onUrlkeyChanged('" . $element->getHtmlId() . "')");
     $element->setOnchange("onUrlkeyChanged('" . $element->getHtmlId() . "')");
     $data = ['name' => $element->getData('name') . '_create_redirect', 'disabled' => true];
     /** @var \Magento\Framework\Data\Form\Element\Hidden $hidden */
     $hidden = $this->_elementFactory->create('hidden', ['data' => $data]);
     $hidden->setForm($element->getForm());
     $storeId = $element->getForm()->getDataObject()->getStoreId();
     $data['html_id'] = $element->getHtmlId() . '_create_redirect';
     $data['label'] = __('Create Permanent Redirect for old URL');
     $data['value'] = $element->getValue();
     $data['checked'] = $this->_scopeConfig->isSetFlag(self::XML_PATH_SEO_SAVE_HISTORY, ScopeInterface::SCOPE_STORE, $storeId);
     /** @var \Magento\Framework\Data\Form\Element\Checkbox $checkbox */
     $checkbox = $this->_elementFactory->create('checkbox', ['data' => $data]);
     $checkbox->setForm($element->getForm());
     return parent::getElementHtml() . '<br/>' . $hidden->getElementHtml() . $checkbox->getElementHtml() . $checkbox->getLabelHtml();
 }
Beispiel #14
0
 /**
  * Render HTML of the element using the rule engine.
  *
  * @return string
  */
 public function getInputHtml()
 {
     $this->rule->setElementName($this->element->getName());
     if ($this->element->getValue()) {
         /* Hack : reload in a new instance to have element name set.
          *        can not be done in afterLoad of the backend model
          *        since we do not know yet the form structure
          */
         $conditions = $this->element->getValue()->getConditions()->asArray();
         $this->rule->getConditions()->loadArray($conditions);
         $this->element->setRule($this->rule);
     }
     $this->input = $this->elementFactory->create('text');
     $this->input->setRule($this->rule)->setRenderer($this->conditions);
     return $this->input->toHtml();
 }
Beispiel #15
0
 /**
  * @param string $type
  * @dataProvider createExceptionInvalidArgumentDataProvider
  * @expectedException \InvalidArgumentException
  */
 public function testCreateExceptionInvalidArgument($type)
 {
     $elementMock = $this->getMock($type, [], [], '', false);
     $this->_objectManagerMock->expects($this->once())->method('create')->with($type, [])->will($this->returnValue($elementMock));
     $this->_factory->create($type);
 }
 /**
  * @return string
  */
 public function getInputHtml()
 {
     $this->input = $this->elementFactory->create('text');
     $this->input->setRule($this->rule)->setRenderer($this->conditions);
     return $this->input->toHtml();
 }
Beispiel #17
0
 /**
  * Get Select field with list of available attribute sets for some target country
  *
  * @param  string $targetCountry
  * @return \Magento\Framework\Data\Form\Element\Select
  */
 public function getAttributeSetsSelectElement($targetCountry)
 {
     $field = $this->_elementFactory->create('select');
     $field->setName('attribute_set_id')->setId('select_attribute_set')->setForm($this->_formFactory->create())->addClass('required-entry')->setValues($this->_getAttributeSetsArray($targetCountry));
     return $field;
 }