本文整理汇总了PHP中Zend\Form\ElementInterface::getMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::getMessages方法的具体用法?PHP ElementInterface::getMessages怎么用?PHP ElementInterface::getMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::getMessages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
public function __invoke(ElementInterface $element = null)
{
if (!empty($element->getMessages())) {
$messages = $element->getMessages();
return sprintf('<span class="glyphicon glyphicon-warning-sign form-control-feedback"
data-toggle="tooltip" title="%s" ></span>', current($messages));
}
}
示例2: render
public function render(ElementInterface $element = null)
{
if ($element->getMessages()) {
$element->setAttribute('class', 'error ' . $element->getAttribute('class'));
}
return parent::render($element);
}
示例3: render
/**
* Render validation errors for the provided $element
*
* @param ElementInterface $element
* @param array $attributes
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element, array $attributes = array())
{
$messages = $element->getMessages();
if (empty($messages)) {
return '';
}
if (!is_array($messages) && !$messages instanceof Traversable) {
throw new Exception\DomainException(sprintf('%s expects that $element->getMessages() will return an array or Traversable; received "%s"', __METHOD__, is_object($messages) ? get_class($messages) : gettype($messages)));
}
// Prepare attributes for opening tag
$attributes = array_merge($this->attributes, $attributes);
$attributes = $this->createAttributesString($attributes);
if (!empty($attributes)) {
$attributes = ' ' . $attributes;
}
// Flatten message array
$escapeHtml = $this->getEscapeHtmlHelper();
$messagesToPrint = array();
$self = $this;
array_walk_recursive($messages, function ($item) use(&$messagesToPrint, $escapeHtml, $self) {
if (null !== ($translator = $self->getTranslator())) {
$item = $translator->translate($item, $self->getTranslatorTextDomain());
}
$messagesToPrint[] = $escapeHtml($item);
});
if (empty($messagesToPrint)) {
return '';
}
// Generate markup
$markup = sprintf($this->getMessageOpenFormat(), $attributes);
$markup .= implode($this->getMessageSeparatorString(), $messagesToPrint);
$markup .= $this->getMessageCloseString();
return $markup;
}
示例4: render
/**
* Render CSS class for the provided $element
*
* @param ElementInterface $element
* @param array $attributes
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element, array $attributes = array())
{
$messages = $element->getMessages();
if (empty($messages)) {
return self::CLASS_NO_ERRORS;
}
return ' ' . self::CLASS_HAS_ERRORS;
}
示例5: render
/**
* render
*
* Render the view helper as a HTML string.
*
* @param ElementInterface $element The form element that should be rendered.
* @param array $options Optional view helper options.
*
* @return string
*/
public function render(ElementInterface $element, array $options = [])
{
$messages = $element->getMessages();
if (!empty($messages)) {
$this->setAttribute('class', array_merge($this->getAttribute('class', []), ['has-error']));
}
return parent::render($element, $options);
}
示例6: __invoke
public function __invoke(ElementInterface $element = null)
{
$messages = $element->getMessages();
if (empty($messages)) {
return '';
}
return sprintf('<div id="cph_Main_ctl00_notification_rptNotice_divMessage_0" class="alert">%s<button data-dismiss="alert" class="close">×</button>
</div>', current($messages));
}
示例7: openTag
/**
* Returns the control group open tag
* @param ElementInterface $element
* @return string
*/
public function openTag(ElementInterface $element)
{
$class = 'control-group';
if ($element->getMessages()) {
$class .= ' error';
}
$html = '<div class="' . $class . '">';
return $html;
}
示例8: __invoke
public function __invoke(ElementInterface $elements = null)
{
if (empty($elements)) {
return "";
}
$message = $elements->getMessages();
return sprintf('<span class="error help-inline">
%s
</span>', current($message));
}
示例9: render
/**
* {@inheritDoc}
*/
public function render(ElementInterface $element, array $attributes = [])
{
$markup = '';
$renderer = $this->getView();
if (!method_exists($renderer, 'plugin')) {
return $markup;
}
/* @var $flashMessenger \Zend\View\Helper\FlashMessenger */
$flashMessenger = $renderer->plugin('flashmessenger');
if ($flashMessenger->hasCurrentMessages() || $element->getMessages()) {
$formName = $element->getName();
foreach ($this->classMessages as $namespace => $class) {
$attribs = $attributes;
if ($namespace === PluginFlashMessenger::NAMESPACE_ERROR) {
$flashMessenger->setTranslatorTextDomain($this->getTranslatorTextDomain());
if (!$this->getMessageOpenFormat()) {
$this->setMessageOpenFormat($flashMessenger->getMessageOpenFormat());
}
if (!$this->getMessageSeparatorString()) {
$this->setMessageSeparatorString($flashMessenger->getMessageSeparatorString());
}
if (!$this->getMessageCloseString()) {
$this->setMessageCloseString($flashMessenger->getMessageCloseString());
}
if ($flashMessenger->hasCurrentMessages() && ($messages = $flashMessenger->getCurrentMessagesFromNamespace("{$formName}-{$namespace}"))) {
$element->setMessages(array_merge($element->getMessages(), $messages));
}
if (isset($attribs['class'])) {
$attribs['class'] .= ' ' . $class;
} else {
$attribs['class'] = $class;
}
$markup .= parent::render($element, $attribs);
} elseif ($flashMessenger->hasCurrentMessages()) {
if (isset($attribs['class'])) {
$class = array_merge((array) $attribs['class'], (array) $class);
}
$markup .= $flashMessenger->renderCurrent("{$formName}-{$namespace}", (array) $class);
}
}
}
return $markup;
}
示例10: openTag
/**
* Returns the control group open tag
* @param ElementInterface $element
* @return string
*/
public function openTag(ElementInterface $element)
{
$class = 'control-group';
$id = 'cgroup-' . $element->getName();
if ($element->getMessages()) {
$class .= ' error';
}
$html = sprintf('<div class="%s" id="%s">', $class, $id);
return $html;
}
示例11: render
/**
* render
*
* Allow the view helper to be callable.
*
* @param ElementInterface $element The element which contains the error messages.
* @param array $options Optional view helper options.
*
* @return string|$this
*/
public function render(ElementInterface $element, array $options)
{
if (!empty($options)) {
$this->setOptions($options);
}
$html = '';
foreach ($element->getMessages() as $type => $message) {
$html .= $this->renderMessage($message, $type);
}
return $html;
}
示例12: isElementHasError
/**
* Helper method. Checks whether $element has error.
*
* @param ElementInterface $element
* @param FormInterface $form
* @return bool
*/
protected function isElementHasError(ElementInterface $element, FormInterface $form)
{
if ($element->getMessages()) {
return true;
}
$elementName = $this->normalizeElementName($element->getName());
$elements = $this->getInvalidFieldsetElements($element, $form);
if (isset($elements[$elementName]) && $elements[$elementName] === $element) {
return true;
}
return false;
}
示例13: render
/**
* Utility form helper that renders a label (if it exists), an element and errors
*
* @param ElementInterface $element
* @throws \Zend\Form\Exception\DomainException
* @return string
*/
public function render(ElementInterface $element, $labelPosition = null)
{
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$elementHelper = $this->getElementHelper();
$elementErrorsHelper = $this->getElementErrorsHelper();
$label = $element->getLabel();
$inputErrorClass = $this->getInputErrorClass();
if (isset($label) && '' !== $label) {
// Translate the label
if (null !== ($translator = $this->getTranslator())) {
$label = $translator->translate($label, $this->getTranslatorTextDomain());
}
}
// Does this element have errors ?
if (count($element->getMessages()) > 0 && !empty($inputErrorClass)) {
$classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : '';
$classAttributes = $classAttributes . $inputErrorClass;
$element->setAttribute('class', $classAttributes);
}
if ($this->partial) {
$vars = array('element' => $element, 'label' => $label, 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $this->labelPosition, 'renderErrors' => $this->renderErrors);
return $this->view->render($this->partial, $vars);
}
$rowOpen = '<div class="form-group">';
$rowClose = '</div>';
$elementString = $elementHelper->render($element);
if ($elementErrorsHelper->render($element)) {
$rowOpen = '<div class="form-group has-error">';
$elementErrors = $elementErrorsHelper->setMessageOpenFormat('<p class="text-danger">')->setMessageSeparatorString('<br />')->setMessageCloseString('</p>')->render($element);
$elementString .= $elementErrors;
}
// hidden elements do not need a <label> -https://github.com/zendframework/zf2/issues/5607
$type = $element->getAttribute('type');
if (isset($label) && '' !== $label && $type !== 'hidden') {
if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
$label = $escapeHtmlHelper($label);
}
if ($label !== '' && !$element->hasAttribute('id') || $element instanceof LabelAwareInterface && $element->getLabelOption('always_wrap')) {
$label = '<label class="col-sm-3 control-label">' . $label . '</label>';
}
$elementString = '<div class="col-sm-9">' . $elementString . '</div>';
// Button element is a special case, because label is always rendered inside it
if ($element instanceof Button || $element instanceof Checkbox || $element instanceof Radio) {
$label = '<div class="col-sm-3"></div>';
}
$markup = $label . $elementString;
} else {
$markup = $elementString;
}
return $rowOpen . $markup . $rowClose;
}
示例14: render
/**
*
* @see FormRow::render()
* @param ElementInterface $oElement
* @return string
*/
public function render(ElementInterface $oElement, $labelPosition = null)
{
$sElementType = $oElement->getAttribute('type');
// Nothing to do for hidden elements which have no messages
if ($sElementType === 'hidden' && !$oElement->getMessages()) {
return parent::render($oElement);
}
// Retrieve expected layout
$sLayout = $oElement->getOption('layout');
// Partial rendering
if ($this->partial) {
return $this->view->render($this->partial, array('element' => $oElement, 'label' => $this->renderLabel($oElement), 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $this->labelPosition, 'renderErrors' => $this->renderErrors));
}
$sRowClass = '';
if (($fgs = $oElement->getOption('form-group-size')) != false) {
$sRowClass = $fgs;
}
// Validation state
if (($sValidationState = $oElement->getOption('validation-state')) != false) {
$sRowClass .= ' has-' . $sValidationState;
}
// "has-error" validation state case
if ($oElement->getMessages()) {
$sRowClass .= ' has-error';
// Element have errors
if (($sInputErrorClass = $this->getInputErrorClass()) != false) {
if (($sElementClass = $oElement->getAttribute('class')) != false) {
if (!preg_match('/(\\s|^)' . preg_quote($sInputErrorClass, '/') . '(\\s|$)/', $sElementClass)) {
$oElement->setAttribute('class', trim($sElementClass . ' ' . $sInputErrorClass));
}
} else {
$oElement->setAttribute('class', $sInputErrorClass);
}
}
}
// Column size
if (($sColumSize = $oElement->getOption('column-size')) && $sLayout !== LeadFilterForm::LAYOUT_HORIZONTAL) {
$sRowClass .= ' col-' . $sColumSize;
}
// Render element
$sElementContent = $this->renderElement($oElement);
// Render form row
if ($sElementType === 'checkbox' && $sLayout !== LeadFilterForm::LAYOUT_HORIZONTAL) {
return $sElementContent . PHP_EOL;
}
if (($sElementType === 'submit' || $sElementType === 'button' || $sElementType === 'reset') && $sLayout === LeadFilterForm::LAYOUT_INLINE) {
return $sElementContent . PHP_EOL;
}
return sprintf(self::$formGroupFormat, $sRowClass, $sElementContent) . PHP_EOL;
}
示例15: __invoke
/**
* @param ElementInterface $element
* @param boolean $block
*
* @return null|string
*/
public function __invoke(ElementInterface $element, $block = false)
{
$messages = $element->getMessages();
if (empty($messages)) {
return null;
}
$errors = array();
foreach ($messages as $message) {
$error = new HtmlElement('span');
$error->addClass($block ? 'help-block' : 'help-inline');
$error->setContent($this->translate((string) $message));
$errors[] = $error;
}
return implode(PHP_EOL, $errors);
}