本文整理汇总了PHP中Zend\Form\ElementInterface::getLabelOption方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::getLabelOption方法的具体用法?PHP ElementInterface::getLabelOption怎么用?PHP ElementInterface::getLabelOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::getLabelOption方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* {@inheritDoc}
*/
public function render(ElementInterface $element)
{
if ($element instanceof LabelAwareInterface) {
if ($element->getLabelOption('always_wrap') !== false) {
$element->setLabelOption('always_wrap', true);
}
}
return parent::render($element);
}
示例2: render
/**
* {@inheritDoc}
*
* @param ElementInterface $element
*/
public function render($content, array $attribs = [], ElementInterface $element = null)
{
if ($content instanceof LabelAwareInterface) {
$content = $content->getLabel();
} elseif ($element instanceof LabelAwareInterface) {
$content = $element->getLabel();
}
if (is_string($content) && $this->hasTranslator() && $this->isTranslatorEnabled()) {
$content = $this->getTranslator()->translate($content, $this->getTranslatorTextDomain());
}
if ($element instanceof FormInterface && ($object = $element->getObject()) && method_exists($object, '__toString')) {
$content = sprintf($content, $object);
}
if ($element && (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape'))) {
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$content = $escapeHtmlHelper($content);
}
return parent::render($content, $attribs);
}
示例3: render
/**
* {@inheritDoc}
*/
public function render($content, array $attribs = [], ElementInterface $element = null)
{
if ($element) {
$srOnly = $this->getSrOnly();
if (null === $srOnly) {
if ($element instanceof LabelAwareInterface) {
if (!$element->getLabel()) {
return '';
}
$srOnly = $element->getLabelOption('sr_only');
}
if (null === $srOnly && $element->hasAttribute('placeholder')) {
$srOnly = true;
}
}
if ($srOnly) {
$attribs = array_merge_recursive($attribs, ['class' => 'sr-only']);
}
}
return parent::render($content, $attribs, $element);
}
示例4: render
/**
* @see FormButton::render()
* @param ElementInterface $oElement
* @param string $sButtonContent
* @throws LogicException
* @throws Exception
* @return string
*/
public function render(ElementInterface $oElement, $sButtonContent = null)
{
if ($sClass = $oElement->getAttribute('class')) {
if (!preg_match('/(\\s|^)btn(\\s|$)/', $sClass)) {
$sClass .= ' btn';
}
if (!preg_match('/(\\s|^)btn-.*(\\s|$)/', $sClass)) {
$sClass .= ' btn-default';
} else {
$bHasOption = false;
foreach (self::$buttonOptions as $sButtonOption) {
if (preg_match('/(\\s|^)btn-' . $sButtonOption . '.*(\\s|$)/', $sClass)) {
$bHasOption = true;
break;
}
}
if (!$bHasOption) {
$sClass .= ' btn-default';
}
}
$oElement->setAttribute('class', trim($sClass));
} else {
$oElement->setAttribute('class', 'btn btn-default');
}
// Retrieve icon options
if (null !== ($aIconOptions = $oElement->getOption('glyphicon'))) {
$sIconHelperMethod = 'glyphicon';
} elseif (null !== ($aIconOptions = $oElement->getOption('fontAwesome'))) {
$sIconHelperMethod = 'fontAwesome';
} elseif (null !== ($aIconOptions = $oElement->getOption('flaticon'))) {
$sIconHelperMethod = 'flaticon';
}
/*
* Define button content
*/
if (null === $sButtonContent) {
$sButtonContent = $oElement->getLabel();
if (!$sButtonContent) {
$sButtonContent = $oElement->getValue();
}
if (null === $sButtonContent && !$aIconOptions) {
throw new DomainException(sprintf('%s expects either button content as the second argument, ' . 'or that the element provided has a label value, a glyphicon option, or a fontAwesome option; none found', __METHOD__));
}
if (null !== ($oTranslator = $this->getTranslator())) {
$sButtonContent = $oTranslator->translate($sButtonContent, $this->getTranslatorTextDomain());
}
}
if (!$oElement instanceof LabelAwareInterface || !$oElement->getLabelOption('disable_html_escape')) {
$oEscapeHtmlHelper = $this->getEscapeHtmlHelper();
$sButtonContent = $oEscapeHtmlHelper($sButtonContent);
}
/*
* Manage icon
*/
if ($aIconOptions) {
if (is_scalar($aIconOptions)) {
$aIconOptions = array('icon' => $aIconOptions, 'position' => self::ICON_PREPEND);
}
if (!is_array($aIconOptions)) {
throw new LogicException(sprintf('"glyphicon" and "fontAwesome" button option expects a scalar value or an array, "%s" given', is_object($aIconOptions) ? get_class($aIconOptions) : gettype($aIconOptions)));
}
$position = 'prepend';
if (!empty($aIconOptions['position'])) {
$position = $aIconOptions['position'];
}
if (!empty($aIconOptions['icon'])) {
$icon = $aIconOptions['icon'];
}
if (!is_scalar($icon)) {
throw new LogicException(sprintf('Glyphicon and fontAwesome "icon" option expects a scalar value, "%s" given', is_object($icon) ? get_class($icon) : gettype($icon)));
} elseif (!is_string($position)) {
throw new LogicException(sprintf('Glyphicon and fontAwesome "position" option expects a string, "%s" given', is_object($position) ? get_class($position) : gettype($position)));
} elseif ($position !== self::ICON_PREPEND && $position !== self::ICON_APPEND) {
throw new LogicException(sprintf('Glyphicon and fontAwesome "position" option allows "' . self::ICON_PREPEND . '" or "' . self::ICON_APPEND . '", "%s" given', is_object($position) ? get_class($position) : gettype($position)));
}
if ($sButtonContent) {
if ($position === self::ICON_PREPEND) {
$sButtonContent = $this->getView()->{$sIconHelperMethod}($icon, isset($aIconOptions['attributes']) ? $aIconOptions['attributes'] : null) . ' ' . $sButtonContent;
} else {
$sButtonContent .= ' ' . $this->getView()->{$sIconHelperMethod}($icon, isset($aIconOptions['attributes']) ? $aIconOptions['attributes'] : null);
}
} else {
$sButtonContent = $this->getView()->{$sIconHelperMethod}($icon, isset($aIconOptions['attributes']) ? $aIconOptions['attributes'] : null);
}
}
/*
* Dropdown button
*/
if ($aDropdownOptions = $oElement->getOption('dropdown')) {
if (!is_array($aDropdownOptions)) {
throw new LogicException(sprintf('"dropdown" option expects an array, "%s" given', is_object($aDropdownOptions) ? get_class($aDropdownOptions) : gettype($aDropdownOptions)));
}
//.........这里部分代码省略.........
示例5: prepareLabel
protected function prepareLabel(ElementInterface $element)
{
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$valuesOptions = $element->getValueOptions();
//append span with c-indicator for each option
foreach ($valuesOptions as $key => $optionSpec) {
if (is_scalar($optionSpec)) {
$optionSpec = ['label' => $optionSpec, 'value' => $key];
}
if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
$optionSpec['label'] = $escapeHtmlHelper($optionSpec['label']);
}
$optionSpec['label'] = '<span class="c-indicator"></span>' . $optionSpec['label'];
$valuesOptions[$key] = $optionSpec;
}
//disable escape because it was already used above
$element->setLabelOption('disable_html_escape', true);
$element->setValueOptions($valuesOptions);
}
示例6: render
/**
* @see \Zend\Form\View\Helper\FormButton::render()
* @param \Zend\Form\ElementInterface $oElement
* @param string $sButtonContent
* @throws \LogicException
* @throws \Exception
* @return string
*/
public function render(\Zend\Form\ElementInterface $oElement, $sButtonContent = null)
{
if ($sClass = $oElement->getAttribute('class')) {
if (!preg_match('/(\\s|^)btn(\\s|$)/', $sClass)) {
$sClass .= ' btn';
}
if (!preg_match('/(\\s|^)btn-.*(\\s|$)/', $sClass)) {
$sClass .= ' btn-default';
} else {
$bHasOption = false;
foreach (self::$buttonOptions as $sButtonOption) {
if (preg_match('/(\\s|^)btn-' . $sButtonOption . '.*(\\s|$)/', $sClass)) {
$bHasOption = true;
break;
}
}
if (!$bHasOption) {
$sClass .= ' btn-default';
}
}
$oElement->setAttribute('class', trim($sClass));
} else {
$oElement->setAttribute('class', 'btn btn-default');
}
//Retrieve glyphicon options
$aGlyphiconOptions = $oElement->getOption('glyphicon');
//Define button content
if (null === $sButtonContent) {
$sButtonContent = $oElement->getLabel();
if (null === $sButtonContent && !$aGlyphiconOptions) {
throw new \DomainException(sprintf('%s expects either button content as the second argument, ' . 'or that the element provided has a label value or a glyphicon option; neither found', __METHOD__));
}
if (null !== ($oTranslator = $this->getTranslator())) {
$sButtonContent = $oTranslator->translate($sButtonContent, $this->getTranslatorTextDomain());
}
}
if (!$oElement instanceof LabelAwareInterface || !$oElement->getLabelOption('disable_html_escape')) {
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$sButtonContent = $escapeHtmlHelper($sButtonContent);
}
//Glyphicon
if ($aGlyphiconOptions) {
if (is_scalar($aGlyphiconOptions)) {
$aGlyphiconOptions = array('icon' => $aGlyphiconOptions, 'position' => self::GLYPHICON_PREPEND);
} elseif (!is_array($aGlyphiconOptions)) {
throw new \LogicException('"glyphicon" button option expects a scalar value or an array, "' . gettype($aGlyphiconOptions) . '" given');
} elseif (!is_scalar($aGlyphiconOptions['icon'])) {
throw new \LogicException('Glyphicon "icon" option expects a scalar value, "' . gettype($aGlyphiconOptions['icon']) . '" given');
} elseif (empty($aGlyphiconOptions['position'])) {
$aGlyphiconOptions['position'] = 'prepend';
} elseif (!is_string($aGlyphiconOptions['position'])) {
throw new \LogicException('Glyphicon "position" option expects a string, "' . gettype($aGlyphiconOptions['position']) . '" given');
} elseif ($aGlyphiconOptions['position'] !== self::GLYPHICON_PREPEND && $aGlyphiconOptions['position'] !== self::GLYPHICON_APPEND) {
throw new \LogicException('Glyphicon "position" option allows "' . self::GLYPHICON_PREPEND . '" or "' . self::GLYPHICON_APPEND . '", "' . $aGlyphiconOptions['position'] . '" given');
}
if ($sButtonContent) {
if ($aGlyphiconOptions['position'] === self::GLYPHICON_PREPEND) {
$sButtonContent = $this->getView()->glyphicon($aGlyphiconOptions['icon'], isset($aGlyphiconOptions['attributes']) ? $aGlyphiconOptions['attributes'] : null) . ' ' . $sButtonContent;
} else {
$sButtonContent .= ' ' . $this->getView()->glyphicon($aGlyphiconOptions['icon'], isset($aGlyphiconOptions['attributes']) ? $aGlyphiconOptions['attributes'] : null);
}
} else {
$sButtonContent = $this->getView()->glyphicon($aGlyphiconOptions['icon'], isset($aGlyphiconOptions['attributes']) ? $aGlyphiconOptions['attributes'] : null);
}
}
//Dropdown button
if ($aDropdownOptions = $oElement->getOption('dropdown')) {
if (!is_array($aDropdownOptions)) {
throw new \LogicException('"dropdown" option expects an array, "' . gettype($aDropdownOptions) . '" given');
}
if (empty($aDropdownOptions['split'])) {
//Class
if (!preg_match('/(\\s|^)dropdown-toggle(\\s|$)/', $sClass = $oElement->getAttribute('class'))) {
$oElement->setAttribute('class', trim($sClass . ' dropdown-toggle'));
}
//data-toggle
$oElement->setAttribute('data-toggle', 'dropdown');
$sMarkup = $this->openTag($oElement) . sprintf(self::$dropdownToggleFormat, $sButtonContent) . $this->closeTag();
} else {
$sMarkup = $this->openTag($oElement) . $sButtonContent . $this->closeTag() . sprintf(self::$dropdownCaretFormat, $oElement->getAttribute('class'));
}
//No container
if ($oElement->getOption('disable-twb')) {
return $sMarkup . $this->getView()->dropdown()->renderListItems($aDropdownOptions);
}
//Render button + dropdown
return sprintf(self::$dropdownContainerFormat, empty($aDropdownOptions['dropup']) ? '' : 'dropup', $sMarkup . $this->getView()->dropdown()->renderListItems($aDropdownOptions));
}
return $this->openTag($oElement) . $sButtonContent . $this->closeTag();
}
示例7: renderDescription
/**
* @param ElementInterface $element
* @return string
*/
protected function renderDescription(ElementInterface $element)
{
if (!($this->getDescriptionWrapper() && ($description = $element->getOption('description')))) {
return '';
}
if (null !== ($translator = $this->getTranslator())) {
$description = $translator->translate($description, $this->getTranslatorTextDomain());
}
if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) {
$escapeHtmlHelper = $this->getEscapeHtmlHelper();
$description = $escapeHtmlHelper($description);
}
return sprintf($this->getDescriptionWrapper(), $description);
}
示例8: render
public function render(\Zend\Form\ElementInterface $oElement)
{
if ($oElement->getOption('value_only') === true) {
$escapeHtml = true;
$sValue = $oElement->getValue();
if ($oElement instanceof \Zend\Form\Element\Select) {
if (!is_array($sValue) && isset($oElement->getValueOptions()[$sValue])) {
$sValue = $oElement->getValueOptions()[$sValue];
} elseif (is_array($sValue)) {
foreach ($sValue as $key => $value) {
if (isset($oElement->getValueOptions()[$value])) {
$sValue[$key] = $oElement->getValueOptions()[$value];
}
}
}
} elseif ($oElement instanceof \Zend\Form\Element\MultiCheckbox) {
if ($oElement->getLabelOption('disable_html_escape')) {
$escapeHtml = false;
}
$valueOptions = $oElement->getValueOptions();
if (!is_array($sValue)) {
$sValue = array($sValue);
}
foreach ($sValue as $key => $value) {
foreach ($valueOptions as $vOpt) {
if ($vOpt['value'] == $value) {
$sValue[$key] = $vOpt['label'];
break;
}
}
}
}
// ignore buttons
if ($oElement instanceof \Zend\Form\Element\Button || $oElement instanceof \Zend\Form\Element\Submit) {
return '';
}
// hide passwords
if ($oElement instanceof \Zend\Form\Element\Password) {
$sValue = '*******';
}
// hide hidden fields
if ($oElement instanceof Hidden) {
$sValue = '';
}
if (is_array($sValue)) {
$sValue = implode(', ', $sValue);
}
$valueHtml = $sValue;
if ($escapeHtml) {
$valueHtml = $this->getEscapeHtmlHelper()->__invoke($valueHtml);
}
if ($oElement->getOption('value_use_pre') === true) {
$valueHtml = '<pre>' . $valueHtml . '</pre>';
}
$hidden = '';
if ($oElement->getOption('add_hidden')) {
// use default hidden element if requested
$hiddenElement = new Hidden($oElement->getName());
$hiddenElement->setValue($oElement->getValue());
$hidden = $this->render($hiddenElement);
}
return sprintf('<div class="%s">%s</div>', 'form-value-only', $valueHtml) . $hidden;
}
return parent::render($oElement);
}