本文整理汇总了PHP中Zend\Form\ElementInterface::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::setAttributes方法的具体用法?PHP ElementInterface::setAttributes怎么用?PHP ElementInterface::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::setAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render(ElementInterface $element)
{
$attributes = $element->getAttributes();
if (isset($attributes['custom'])) {
$custom = $attributes['custom'];
unset($attributes['custom']);
$element->setAttributes($attributes);
}
$prefix = '';
$suffix = '';
// Check on name for now
if ($attributes['type'] === 'text' && $attributes['name'] === 'email') {
$prefix .= '<div class="input-group">';
$prefix .= '<span class="input-group-addon">@</span>';
$suffix .= '<span class="input-group-addon" id="basic-addon2">@example.com</span>';
$suffix .= '</div>';
} elseif ($attributes['type'] === 'text' && $attributes['name'] === 'keyword') {
$prefix .= '<div class="input-group">';
$suffix .= '<span class="input-group-btn">';
$suffix .= sprintf('<button class="btn btn-default" type="submit">%s</button>', $custom['label']);
$suffix .= '</span>';
}
return $prefix . parent::render($element) . $suffix;
}
示例2: render
/**
* Renders the form row as a bootstrap form row
*
* @param ElementInterface $element
* @param null $labelPosition
* @return string
*/
public function render(ElementInterface $element, $labelPosition = null)
{
if ($element->getAttribute('type') != 'submit') {
$elementAttributes = $element->getAttributes();
if (isset($elementAttributes['class']) && $elementAttributes['class'] != null) {
$elementAttributes['class'] .= ' form-control';
} else {
$elementAttributes['class'] = 'form-control';
}
$element->setAttributes($elementAttributes);
}
$row = parent::render($element, $labelPosition);
return '<div class="form-group">' . $row . '</div>';
}
示例3: render
/**
* @param ElementInterface $element
* @return string|void
*/
public function render(ElementInterface $element)
{
$twitter = $element->getOption('twitter_date');
$twitter = empty($twitter) ? array() : $twitter;
$hasButton = !empty($twitter['has-button']) || !empty($twitter['has_button']);
unset($twitter['has-button']);
unset($twitter['has_button']);
$attrs = $element->getAttributes();
if ($hasButton) {
$attrsw = array('class' => 'input-append date', 'id' => 'div-' . $attrs['id']);
$attrsw = Utils::arrayMergeRecursiveRight($attrsw, $twitter);
$openW = '<div ' . $this->createAttributesString($attrsw) . '>';
$closeW = '<span class="add-on"><i class="icon-calendar"></i></span></div>';
} else {
$attrs = Utils::arrayMergeRecursiveRight($attrs, $twitter);
$element->setAttributes($attrs);
$openW = '';
$closeW = '';
}
return $openW . parent::render($element) . $closeW;
}
示例4: render
public function render(ElementInterface $element = null)
{
/* @var \Zend\View\Renderer\PhpRenderer $view */
$view = $this->getView();
/* @var \Zend\View\Helper\HeadScript $headScript */
$headScript = $view->plugin('headscript');
/* @var \Zend\View\Helper\BasePath $basePath */
$basePath = $view->plugin('basePath');
$params = $view->plugin('params');
/* @var \Core\View\Helper\Params $params */
$lang = $params('lang');
$headScript->appendFile($basePath('/js/bootstrap-datepicker/js/bootstrap-datepicker.min.js'));
if (in_array($this->language, ['de'])) {
$headScript->appendFile($basePath('/js/bootstrap-datepicker/locales/bootstrap-datepicker.de.min.js'));
}
$element->setAttributes(['data-date-language' => $lang, 'data-provide' => 'datepicker', 'data-date-format' => 'yyyy-mm-dd']);
$input = parent::render($element);
/*
*
*/
$markup = '<div class="input-group date">%s<div data-toggle="description" data-target="%s" class="input-group-addon" onClick="$(this).parent().find(\':input\').datepicker(\'show\')">' . '<i class="fa fa-calendar"></i></div></div><div class="checkbox"></div>';
$markup = sprintf($markup, $input, $element->getAttribute('id'));
return $markup;
}
示例5: configureElement
/**
* Configure an element based on the provided specification
*
* Specification can contain any of the following:
* - type: the Element class to use; defaults to \Zend\Form\Element
* - name: what name to provide the element, if any
* - options: an array, Traversable, or ArrayAccess object of element options
* - attributes: an array, Traversable, or ArrayAccess object of element
* attributes to assign
*
* @param ElementInterface $element
* @param array|Traversable|ArrayAccess $spec
* @throws Exception\DomainException
* @return ElementInterface
*/
public function configureElement(ElementInterface $element, $spec)
{
$spec = $this->validateSpecification($spec, __METHOD__);
$name = isset($spec['name']) ? $spec['name'] : null;
$options = isset($spec['options']) ? $spec['options'] : null;
$attributes = isset($spec['attributes']) ? $spec['attributes'] : null;
if ($name !== null && $name !== '') {
$element->setName($name);
}
if (is_array($options) || $options instanceof Traversable || $options instanceof ArrayAccess) {
$element->setOptions($options);
}
if (is_array($attributes) || $attributes instanceof Traversable || $attributes instanceof ArrayAccess) {
$element->setAttributes($attributes);
}
return $element;
}