本文整理汇总了PHP中Zend\Form\ElementInterface::getAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::getAttributes方法的具体用法?PHP ElementInterface::getAttributes怎么用?PHP ElementInterface::getAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::getAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @throws \Zend\Form\Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof CheckboxElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$checkedValue = $element->getCheckedValue();
$uncheckedValue = $element->getUncheckedValue();
$useHiddenElement = $element->useHiddenElement();
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['checked'] = '';
$attributes['type'] = $this->getInputType();
$closingBracket = $this->getInlineClosingBracket();
$value = $element->getValue();
if ($value === $checkedValue) {
$attributes['checked'] = 'checked';
}
$attributes['value'] = $checkedValue;
$rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
if ($useHiddenElement) {
$hiddenAttributes = array('name' => $attributes['name'], 'value' => $uncheckedValue);
$rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
}
return $rendered;
}
示例2: render
/**
* Render a form <select> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof SelectElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Select', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$options = $element->getValueOptions();
if (($emptyOption = $element->getEmptyOption()) !== null) {
$options = array('' => $emptyOption) + $options;
}
$attributes = $element->getAttributes();
$value = $this->validateMultiValue($element->getValue(), $attributes);
$attributes['name'] = $name;
if (array_key_exists('multiple', $attributes) && $attributes['multiple']) {
$attributes['name'] .= '[]';
}
$this->validTagAttributes = $this->validSelectAttributes;
$size = $element->getOption('size');
if (empty($size)) {
return sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value));
}
return sprintf('<div class="col-lg-%s col-md-%s col-sm-%s col-xs-%s">
<select %s>%s</select>
</div>', $size, $size, $size, $size, $this->createAttributesString($attributes), $this->renderOptions($options, $value));
}
示例3: render
public function render(ElementInterface $element)
{
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$content = (string) $element->getValue();
$escapeHtml = $this->getEscapeHtmlHelper();
//ADD OPTIONS
// this should really be in Stjonvisi\Form\Element\Img
// but it gets overwritten at some point, so the simplest
// thing was to add it here.
// TODO place this i a more generic place
$element->setOption('max', $this->getMaxSize())->setOption('mime', '/image\\/jpg|png|gif/')->setOption('url', '/skrar/mynd');
//OPTIONS
// options are used to set attributes and values
// to the custom element. We therefore need to remove
// label, label_attributes and label_options before we
// can convert them into an attribute string.
$options = $element->getOptions();
unset($options['label']);
unset($options['label_attributes']);
unset($options['label_options']);
$strings = array_map(function ($key, $value) {
return sprintf('%s="%s"', $key, $value);
}, array_keys($options), $options);
return sprintf('<stjornvisi-rich %s><textarea %s>%s</textarea></stjornvisi-rich>', implode(' ', $strings), $this->createAttributesString($attributes), $escapeHtml($content));
}
示例4: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element Zend Form Element
*
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof CheckboxElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getInputType();
$attributes['value'] = $element->getCheckedValue();
$closingBracket = $this->getInlineClosingBracket();
if ($element->isChecked()) {
$attributes['checked'] = 'checked';
}
if ($element->getAttribute('class') != 'input-checkbox') {
$rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
} else {
if ($element->getAttribute('id') == '') {
$element->setAttribute('id', 'checkbox-' . uniqid());
}
unset($attributes['class']);
$rendered = sprintf('<span class="input-checkbox"><input %s%s<label for="%s"></label></span>', $this->createAttributesString($attributes), $closingBracket, $element->getAttribute('id'));
}
return $rendered;
}
示例5: 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;
}
示例6: render
/**
* Render a form checkbox-group element from the provided $element
*
* @param \Zend\Form\ElementInterface $element
* @throws \Zend\Form\Exception\InvalidArgumentException
* @throws \Zend\Form\Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof TagBanners) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Grid\\Banner\\Form\\Element\\TagBanners', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$appService = $this->getAppServiceHelper();
$tagModel = $appService('Grid\\Tag\\Model\\Tag\\Model');
$attributes = $element->getAttributes();
$value = (array) $element->getValue();
$groups = array();
foreach ($value as $tagId => $banners) {
$tag = $tagModel->find($tagId);
if ($tag && $tag->locale) {
$locale = 'locale.sub.' . $tag->locale;
if ($this->isTranslatorEnabled() && $this->hasTranslator()) {
$locale = $this->getTranslator()->translate($locale, 'locale');
}
}
$label = $tag ? $tag->name . (isset($locale) ? ' (' . $locale . ')' : '') : '#' . $tagId;
$groups[] = array('header' => $label, 'markup' => $this->renderBanners($name . '[' . $tagId . ']', $banners), 'attributes' => array('data-tagid' => $tagId));
}
unset($attributes['name']);
return $this->renderBannerGroups($name . '[__tagid__]', $attributes, $groups);
}
示例7: render
/**
* Render a form <select> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof SelectElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Select', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$options = $element->getValueOptions();
if (($emptyOption = $element->getEmptyOption()) !== null) {
$options = array('' => $emptyOption) + $options;
}
$attributes = $element->getAttributes();
$value = $this->validateMultiValue($element->getValue(), $attributes);
$attributes['name'] = $name;
if (array_key_exists('multiple', $attributes) && $attributes['multiple']) {
$attributes['name'] .= '[]';
}
$this->validTagAttributes = $this->validSelectAttributes;
$rendered = sprintf('<select %s>%s</select>', $this->createAttributesString($attributes), $this->renderOptions($options, $value));
// Render hidden element
$useHiddenElement = method_exists($element, 'useHiddenElement') && method_exists($element, 'getUnselectedValue') && $element->useHiddenElement();
if ($useHiddenElement) {
$rendered = $this->renderHiddenElement($element) . $rendered;
}
return $rendered;
}
示例8: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
$name = $element->getName();
if ($name === null || $name === '') {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['type'] = $this->getType($element);
$attributes['name'] = $name;
if (array_key_exists('multiple', $attributes) && $attributes['multiple']) {
$attributes['name'] .= '[]';
}
$value = $element->getValue();
if (is_array($value) && isset($value['name']) && !is_array($value['name'])) {
$attributes['value'] = $value['name'];
} elseif (is_string($value)) {
$attributes['value'] = $value;
}
$size = $element->getOption('size');
if (empty($size)) {
return sprintf('<input %s%s', $this->createAttributesString($attributes), $this->getInlineClosingBracket());
}
return sprintf('<div class="col-lg-%s col-md-%s col-sm-%s col-xs-%s">
<input %s%s
</div>', $size, $size, $size, $size, $this->createAttributesString($attributes), $this->getInlineClosingBracket());
}
示例9: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof CheckboxElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getInputType();
$attributes['value'] = $element->getCheckedValue();
$attributes['class'] = 'sr-only';
$closingBracket = $this->getInlineClosingBracket();
if ($element->isChecked()) {
$attributes['checked'] = 'checked';
}
$input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
$label = $element->getLabel();
$rendered = '<div class="checkbox"><label class="checkbox-custom" data-initialize="checkbox">' . $input . '<span class="checkbox-label">' . $label . '</span>' . '</label></div>';
if ($element->useHiddenElement()) {
$hiddenAttributes = array('name' => $attributes['name'], 'value' => $element->getUncheckedValue());
$rendered = sprintf('<input type="hidden" %s%s', $this->createAttributesString($hiddenAttributes), $closingBracket) . $rendered;
}
return $rendered;
}
示例10: render
/**
* Render a form checkbox-group element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof MultiCheckboxGroup) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zork\\Form\\Element\\MutiCheckboxGroup', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$options = $element->getValueOptions();
if (empty($options)) {
if (($translator = $this->getTranslator()) !== null) {
return '<i>' . $translator->translate('default.empty', 'default') . '</i>';
} else {
return '';
}
}
if (($emptyOption = $element->getEmptyOption()) !== null) {
$options = array('' => $emptyOption) + $options;
}
$attributes = $element->getAttributes();
$value = $element->getValue();
$addAttr = array('type' => 'checkbox', 'name' => substr($name, -2) == '[]' ? $name : $name . '[]', 'required' => empty($attributes['required']) ? null : 'required');
$this->validTagAttributes = $this->validCheckboxGroupAttributes;
if (null !== $element->getTranslatorTextDomain()) {
$this->setTranslatorTextDomain($element->getTranslatorTextDomain());
}
if (empty($attributes['class'])) {
$attributes['class'] = 'multi_checkbox';
}
return sprintf('<div %s>%s</div>', $this->createAttributesString($attributes), sprintf('<input type="hidden" name="%s" value="" />' . PHP_EOL, substr($name, -2) == '[]' ? substr($name, 0, -2) : $name) . $this->renderCheckboxes($options, $value, $addAttr));
}
示例11: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
$name = $element->getName();
if ($name === null || $name === '') {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getType($element);
$attributes['value'] = $element->getValue();
//ADD OPTIONS
// this should really be in Stjonvisi\Form\Element\Img
// but it gets overwritten at some point, so the simplest
// thing was to add it here.
// TODO place this i a more generic place
$element->setOption('max', $this->getMaxSize())->setOption('url', '/skrar/mynd')->setOption('accept', 'image/*')->setOption('mime', '/image\\/jpg|jpeg|png|gif/');
//OPTIONS
// options are used to set attributes and values
// to the custom element. We therefore need to remove
// label, label_attributes and label_options before we
// can convert them into an attribute string.
$options = $element->getOptions();
unset($options['label']);
unset($options['label_attributes']);
unset($options['label_options']);
$strings = array_map(function ($key, $value) {
return sprintf('%s="%s"', $key, $value);
}, array_keys($options), $options);
return sprintf('<stjornvisi-img %s><input %s%s</stjornvisi-img>', implode(' ', $strings), $this->createAttributesString($attributes), $this->getInlineClosingBracket());
}
示例12: render
public function render(ElementInterface $element)
{
$attributes = $element->getAttributes();
// echo $this->createAttributesString($attributes);
return sprintf('<video width="%s" height="%s" controls>
<source src="%s" type="%s">
</video>', $attributes['width'], $attributes['height'], $attributes['src'], $attributes['type']);
}
示例13: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = 'text';
$attributes['class'] = 'form-control';
$attributes['value'] = $element->getValue();
$attributes['date'] = $element->getValue();
$attributes['readonly'] = 'readonly';
$closingBracket = $this->getInlineClosingBracket();
$jsAttributes = array();
if (isset($attributes['allowPastDates'])) {
$jsAttributes['allowPastDates'] = $attributes['allowPastDates'];
unset($attributes['allowPastDates']);
}
if (isset($attributes['date'])) {
$jsAttributes['date'] = $attributes['date'];
unset($attributes['date']);
}
if (isset($attributes['formatDate'])) {
$jsAttributes['formatDate'] = $attributes['formatDate'];
unset($attributes['formatDate']);
}
if (isset($attributes['momentConfig'])) {
$jsAttributes['momentConfig'] = $attributes['momentConfig'];
unset($attributes['momentConfig']);
}
if (isset($attributes['sameYearOnly'])) {
$jsAttributes['sameYearOnly'] = $attributes['sameYearOnly'];
unset($attributes['sameYearOnly']);
}
$script = $this->scriptAttributes($name, $jsAttributes);
$input = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
$wrapper = '<div class="dropdown-menu dropdown-menu-right datepicker-calendar-wrapper" role="menu">';
$wrapper .= $this->calendar();
$wrapper .= $this->monthWheel();
$wrapper .= '</div>';
$datePicker = '<div class="input-group">';
$datePicker .= $input;
$datePicker .= '<div class="input-group-btn">';
$datePicker .= '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">';
$datePicker .= '<span class="glyphicon glyphicon-calendar"></span>';
$datePicker .= '<span class="sr-only">Toggle Calendar</span>';
$datePicker .= '</button>';
$datePicker .= $wrapper;
$datePicker .= '</div>';
$datePicker .= '</div>';
$rendered = $script . '<div class="datepicker" id="' . $name . '">' . $datePicker . '</div>';
return $rendered;
}
示例14: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @return string
*/
public function render(ElementInterface $element)
{
$name = $element->getName();
if ($name === null || $name === '') {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getType($element);
return sprintf('<input %s%s', $this->createAttributesString($attributes), $this->getInlineClosingBracket());
}
示例15: initFormElement
/**
* @param ElementInterface $element
*
* @return \SxBootstrap\View\Helper\Bootstrap\Form\Input
*/
protected function initFormElement(ElementInterface $element)
{
$this->name($element->getName())->type('text');
$this->getElement()->addAttributes($element->getAttributes());
$type = $element->getAttribute('type');
if (null !== $type) {
$this->type(strtolower($type));
}
$this->value($element->getValue());
return $this;
}