magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

The zero-valued parameters are missed in the widget code, generated by the TinyMCE editor

Open quynhvv opened this issue 10 years ago • 2 comments

Hi guys, When insert a widget via TinyMCE editor, we can't not get param with values is zero in the widget short code generated. I have detected and see the root of issue at below function: (vendor/magento/module-widget/Model/Widget.php)

 public function getWidgetDeclaration($type, $params = [], $asIs = true)
    {
        $directive = '{{widget type="' . $type . '"';

        foreach ($params as $name => $value) {
            // Retrieve default option value if pre-configured
            if ($name == 'conditions') {
                $name = 'conditions_encoded';
                $value = $this->conditionsHelper->encode($value);
            } elseif (is_array($value)) {
                $value = implode(',', $value);
            } elseif (trim($value) == '') {
                $widget = $this->getConfigAsObject($type);
                $parameters = $widget->getParameters();
                if (isset($parameters[$name]) && is_object($parameters[$name])) {
                    $value = $parameters[$name]->getValue();
                }
            }
            if ($value) {
                $directive .= sprintf(' %s="%s"', $name, $value);
            }
        }
        $directive .= '}}';

        if ($asIs) {
            return $directive;
        }

        $html = sprintf(
            '<img id="%s" src="%s" title="%s">',
            $this->idEncode($directive),
            $this->getPlaceholderImageUrl($type),
            $this->escaper->escapeUrl($directive)
        );
        return $html;
    }

We have change to:

 public function getWidgetDeclaration($type, $params = [], $asIs = true)
    {
        $directive = '{{widget type="' . $type . '"';

        foreach ($params as $name => $value) {
            // Retrieve default option value if pre-configured
            if ($name == 'conditions') {
                $name = 'conditions_encoded';
                $value = $this->conditionsHelper->encode($value);
            } elseif (is_array($value)) {
                $value = implode(',', $value);
            } elseif (trim($value) == '') {
                $widget = $this->getConfigAsObject($type);
                $parameters = $widget->getParameters();
                if (isset($parameters[$name]) && is_object($parameters[$name])) {
                    $value = $parameters[$name]->getValue();
                }
            }
//            if ($value) {
                $directive .= sprintf(' %s="%s"', $name, $value);
//            }
        }
        $directive .= '}}';

        if ($asIs) {
            return $directive;
        }

        $html = sprintf(
            '<img id="%s" src="%s" title="%s">',
            $this->idEncode($directive),
            $this->getPlaceholderImageUrl($type),
            $this->escaper->escapeUrl($directive)
        );
        return $html;
    }

Please have a look. Regards, Quynhvv.

quynhvv avatar Mar 28 '16 02:03 quynhvv

Confirmed, internal issue MAGETWO-54159

piotrekkaminski avatar Jun 10 '16 00:06 piotrekkaminski

Closed as has been already fixed in 5099ab40 b3e4c3bb2 e7ae8f3c

veloraven avatar Oct 26 '16 08:10 veloraven