Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
quynhvv opened this issue Mar 28, 2016 · 2 comments

Comments

@quynhvv
Copy link

quynhvv commented Mar 28, 2016

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.

@piotrekkaminski
Copy link
Contributor

Confirmed, internal issue MAGETWO-54159

@piotrekkaminski piotrekkaminski self-assigned this Jun 10, 2016
okorshenko pushed a commit that referenced this issue Jul 6, 2016
okorshenko pushed a commit that referenced this issue Jul 6, 2016
@vkorotun vkorotun removed the PS label Aug 4, 2016
@piotrekkaminski piotrekkaminski removed their assignment Aug 22, 2016
@veloraven
Copy link
Contributor

Closed as has been already fixed in 5099ab4 b3e4c3b e7ae8f3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants