Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

FormButton $buttonContent parameter is now translated #7184

Conversation

Victory
Copy link
Contributor

@Victory Victory commented Feb 5, 2015

In master if you pass in a $buttonContent parameter to Zend\Form\View\Helper\FormButton the $buttonContent is not translated.

Zend\Form\View\Helper\FormButton->_invoke($element, "translate me")

This pull requests creates a test to show the error and a fix to this issue.

@@ -91,6 +91,12 @@ public function render(ElementInterface $element, $buttonContent = null)
$buttonContent, $this->getTranslatorTextDomain()
);
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the extra else. You can simply move the first if:

/**
 * Render a form <button> element from the provided $element,
 * using content from $buttonContent or the element's "label" attribute
 *
 * @param  ElementInterface $element
 * @param  null|string $buttonContent
 * @throws Exception\DomainException
 * @return string
 */
public function render(ElementInterface $element, $buttonContent = null)
{
    $openTag = $this->openTag($element);

    if (null === $buttonContent) {
        $buttonContent = $element->getLabel();
        if (null === $buttonContent) {
            throw new Exception\DomainException(sprintf(
                '%s expects either button content as the second argument, ' .
                    'or that the element provided has a label value; neither found',
                __METHOD__
            ));
        }
    }

    if (null !== ($translator = $this->getTranslator())) {
        $buttonContent = $translator->translate(
            $buttonContent, $this->getTranslatorTextDomain()
        );
    }

    if (! $element instanceof LabelAwareInterface || ! $element->getLabelOption('disable_html_escape')) {
        $escapeHtmlHelper = $this->getEscapeHtmlHelper();
        $buttonContent = $escapeHtmlHelper($buttonContent);
    }

    return $openTag . $buttonContent . $this->closeTag();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, i have added the changes and pushed.

@Victory
Copy link
Contributor Author

Victory commented Feb 6, 2015

There seems to be some unrelated failing tests in "ZendTest\Cache\Storage\Adapter\DbaInifileTest" on travis. The test in this pull request passes.

@weierophinney weierophinney added this to the 2.4.0 milestone Feb 19, 2015
weierophinney added a commit that referenced this pull request Feb 25, 2015
…aram

FormButton $buttonContent parameter is now translated
weierophinney added a commit that referenced this pull request Feb 25, 2015
@weierophinney
Copy link
Member

Merged to develop for release with 2.4.

@Victory
Copy link
Contributor Author

Victory commented Feb 25, 2015

thanks as always @weierophinney !

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

Successfully merging this pull request may close these issues.

None yet

3 participants