sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function passwordInput($options = [])
{
$options = array_merge($this->inputOptions, $options);
$this->initCharacterCounter($options);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activePasswordInput($this->model, $this->attribute, $options);
return $this;
}
|
Renders a password input.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [\yii\helpers\BaseHtml::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#encode()-detail).
The following special options are recognized:
- `maxlength`: integer|boolean, when `maxlength` is set `true` and the model attribute is validated
by a string validator, the `maxlength` and `length` option both option will take the value of
[\yii\validators\StringValidator::max](http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html#$max-detail).
- `showCharacterCounter`: boolean, when this option is set `true` and the `maxlength` option is set accordingly
the Materialize character counter JS plugin is initialized for this field.
@return $this the field object itself.
@see http://materializecss.com/forms.html#character-counter
|
entailment
|
public function searchInput($options = [])
{
Html::addCssClass($options, ['input' => 'search']);
$this->initAutoComplete($options);
return parent::input('search', $options);
}
|
Renders a search input.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [\yii\helpers\BaseHtml::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#encode()-detail).
The following special options are recognized:
- autocomplete: string|array, see [[initAutoComplete()]] for details.
@return ActiveField the field itself.
|
entailment
|
public function telInput($options = [])
{
Html::addCssClass($options, ['input' => 'tel']);
$this->initAutoComplete($options);
return parent::input('tel', $options);
}
|
Renders a phone input.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [\yii\helpers\BaseHtml::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#encode()-detail).
The following special options are recognized:
- autocomplete: string|array, see [[initAutoComplete()]] for details.
@return ActiveField the field itself.
|
entailment
|
public function textarea($options = [])
{
$this->initAutoComplete($options);
$this->initCharacterCounter($options);
Html::addCssClass($options, ['textarea' => 'materialize-textarea']);
$options = array_merge($this->inputOptions, $options);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeTextarea($this->model, $this->attribute, $options);
return $this;
}
|
Renders a textarea.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [\yii\helpers\BaseHtml::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#encode()-detail).
The following special options are recognized:
- `maxlength`: integer|boolean, when `maxlength` is set `true` and the model attribute is validated
by a string validator, the `maxlength` and `length` option both option will take the value of
[\yii\validators\StringValidator::max](http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html#$max-detail).
- `showCharacterCounter`: boolean, when this option is set `true` and the `maxlength` option is set accordingly
the Materialize character counter JS plugin is initialized for this field.
- autocomplete: string|array, see [[initAutoComplete()]] for details
@return $this the field object itself.
@see http://materializecss.com/forms.html#character-counter
@see http://materializecss.com/forms.html#autocomplete
@see https://www.w3.org/TR/html5/forms.html#attr-fe-autocomplete
|
entailment
|
public function timeInput($options = [])
{
Html::addCssClass($options, ['input' => 'time']);
$this->initAutoComplete($options);
return parent::input('time', $options);
}
|
Renders a time input.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [\yii\helpers\BaseHtml::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#encode()-detail).
The following special options are recognized:
- autocomplete: string|array, see [[initAutoComplete()]] for details.
@return ActiveField the field itself.
|
entailment
|
public function urlInput($options = [])
{
Html::addCssClass($options, ['input' => 'url']);
$this->initAutoComplete($options);
return parent::input('url', $options);
}
|
Renders an URL input.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [\yii\helpers\BaseHtml::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#encode()-detail).
The following special options are recognized:
- autocomplete: string|array, see [[initAutoComplete()]] for details.
@return ActiveField the field itself.
|
entailment
|
public function weekInput($options = [])
{
Html::addCssClass($options, ['input' => 'week']);
$this->initAutoComplete($options);
return parent::input('week', $options);
}
|
Renders a week input.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [\yii\helpers\BaseHtml::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#encode()-detail).
The following special options are recognized:
- autocomplete: string|array, see [[initAutoComplete()]] for details.
@return ActiveField the field itself.
|
entailment
|
public function init()
{
parent::init();
if (!$this->name) {
throw new InvalidConfigException('The icon name must be specified.');
}
if ($this->position === null) {
$this->position = 'left';
}
Html::addCssClass($this->options, ['material-icons', $this->position]);
}
|
Initializes the widget.
@throws InvalidConfigException if icon name is not specified
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'i');
return Html::tag($tag, $this->name, $this->options);
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->options, ['widget' => 'progress']);
Html::addCssClass($this->progressOptions, ['type' => $this->type]);
if ($this->type === self::TYPE_DETERMINATE) {
Html::addCssStyle($this->progressOptions, ['width' => $this->value . '%']);
}
}
|
Initializes the widget.
|
entailment
|
public function run()
{
$html[] = Html::beginTag('div', $this->options);
$html[] = Html::tag('div', null, $this->progressOptions);
$html[] = Html::endTag('div');
return implode("\n", $html);
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
|
entailment
|
protected function initDefaultButtons()
{
if (!isset($this->buttons['view'])) {
$this->buttons['view'] = function ($url, $model, $key) {
$options = ArrayHelper::merge([
'title' => Yii::t('yii', 'View'),
'aria-label' => Yii::t('yii', 'View'),
], $this->buttonOptions);
return Html::a(Icon::widget([
'name' => 'visibility',
]), $url, $options);
};
}
if (!isset($this->buttons['update'])) {
$this->buttons['update'] = function ($url, $model, $key) {
$options = ArrayHelper::merge([
'title' => Yii::t('yii', 'Update'),
'aria-label' => Yii::t('yii', 'Update'),
], $this->buttonOptions);
return Html::a(Icon::widget([
'name' => 'edit',
]), $url, $options);
};
}
if (!isset($this->buttons['delete'])) {
$this->buttons['delete'] = function ($url, $model, $key) {
$options = ArrayHelper::merge([
'title' => Yii::t('yii', 'Delete'),
'aria-label' => Yii::t('yii', 'Delete'),
'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
'data-method' => 'post',
], $this->buttonOptions);
return Html::a(Icon::widget([
'name' => 'delete',
]), $url, $options);
};
}
}
|
Initializes the default button rendering callbacks.
This method uses [[Icon|Icon]] to display iconic buttons.
|
entailment
|
protected function registerPlugin($name, $selector = null)
{
/** @var View $view */
$view = $this->getView();
MaterializePluginAsset::register($view);
$id = $this->options['id'];
if (is_null($selector)) {
$selector = '#' . $id;
}
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);
$js = "document.addEventListener('DOMContentLoaded', function() {M.$name.init(document.querySelectorAll('$selector'), $options);});";
$view->registerJs($js, View::POS_END);
}
$this->registerClientEvents();
}
|
Registers a specific Materialize plugin and the related events.
@param string $name the name of the Materialize plugin
@param string|null $selector the name of the selector the plugin shall be attached to
@uses [yii\helper\BaseJson::encode()](http://www.yiiframework.com/doc-2.0/yii-helpers-basejson.html#encode()-detail)
to encode the [[clientOptions]]
@uses [[MaterializePluginAsset::register()]]
@uses [[registerClientEvents()]]
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->options, ['container' => 'switch']);
if ($this->hasModel()) {
if (!isset($this->inputOptions['name'])) {
$this->inputOptions['name'] = Html::getInputName($this->model, $this->attribute);
}
if (!isset($this->inputOptions['id'])) {
$this->inputOptions['id'] = Html::getInputId($this->model, $this->attribute);
}
} else {
$this->inputOptions['name'] = $this->name;
}
$this->inputOptions['uncheck'] = isset($this->uncheck) ? $this->uncheck : is_null($this->uncheck) ? null : '0';
$this->inputOptions['value'] = isset($this->value) ? $this->value : '1';
}
|
Initialize the widget.
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html = Html::beginTag($tag, $this->options);
$html .= $this->renderSwitch();
$html .= Html::endTag($tag);
return $html;
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
@uses [[renderSwitch()]]
|
entailment
|
protected function renderSwitch()
{
$value = ArrayHelper::getValue($this->inputOptions, 'value', null);
if ($this->hasModel()) {
$attributeValue = Html::getAttributeValue($this->model, $this->attribute);
$this->checked = "{$value}" === "{$attributeValue}";
}
$name = ArrayHelper::remove($this->inputOptions, 'name', null);
return implode("\n", [
Html::beginTag('label'),
$this->renderLabel('off'),
Html::checkbox($name, $this->checked, $this->inputOptions),
Html::tag('span', '', ['class' => 'lever']),
$this->renderLabel('on'),
Html::endTag('label'),
]);
}
|
Render the switch button checkbox.
@return string
@uses [yii\helper\BaseHtml::checkbox()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#checkbox()-detail)
|
entailment
|
protected function renderLabel($state)
{
$icon = $this->renderIcon($state);
$encodeProperty = "encode" . ucfirst($state) . "Text";
$textProperty = "{$state}Text";
$label = $this->$encodeProperty ? Html::encode($this->$textProperty) : $this->$textProperty;
$label .= $icon;
$html = [];
$html[] = Html::beginTag('span', ['class' => "{$state}Label"]);
$html[] = $label;
$html[] = Html::endTag('span');
return implode("\n", $html);
}
|
Renders the HTML markup for the on/off label.
This method also renders the corresponding icons, if set.
@param string $state the state to used. Use "off" or "on".
@return string the rendered label.
@uses [[Icon|Icon]]
|
entailment
|
protected function renderIcon($state)
{
$iconProperty = "{$state}Icon";
if (!$this->$iconProperty) {
return '';
}
return Icon::widget([
'name' => ArrayHelper::getValue($this->$iconProperty, 'name', null),
'position' => ArrayHelper::getValue($this->$iconProperty, 'position', null),
'options' => ArrayHelper::getValue($this->$iconProperty, 'options', [])
]);
}
|
Renders an icon.
@param string $state the name of the icon property.
@return string the rendered icon
@uses http://www.yiiframework.com/doc-2.0/yii-helpers-basearrayhelper.html#getValue()-detail
@see Icon::run
|
entailment
|
public function init()
{
parent::init();
if (!$this->imageSrc) {
$imageSrc = ArrayHelper::remove($this->imageOptions, 'src', null);
if (!$imageSrc) {
throw new InvalidConfigException("Image src must be defined.");
}
$this->imageSrc = $imageSrc;
}
$this->registerPlugin('Parallax', '.parallax');
}
|
Initialize the widget.
@throws InvalidConfigException
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);
$html[] = Html::beginTag('div', ['class' => 'parallax-container']);
$html[] = Html::beginTag('div', ['class' => 'parallax']);
$html[] = Html::img($this->imageSrc, $this->imageOptions);
$html[] = Html::endTag('div');
$html[] = Html::endTag('div');
$html[] = Html::endTag($tag);
return implode("\n", $html);
}
|
Execute the widget.
@return string the widget's markup.
|
entailment
|
public function run()
{
MaterializeAsset::register($this->getView());
$html[] = $this->renderItems();
return implode("\n", $html);
}
|
Renders the widget.
|
entailment
|
protected function renderDropdown($items, $parentItem, $targetId)
{
$dropdownOptions = ArrayHelper::getValue($parentItem, 'dropDownOptions', []);
if (!isset($dropdownOptions['id'])) {
$dropdownOptions['id'] = $targetId;
}
return Dropdown::widget([
'options' => $dropdownOptions,
'items' => $items,
'encodeLabels' => $this->encodeLabels,
'toggleButtonOptions' => false,
]);
}
|
Renders the given items as a dropdown.
This method is called to create sub-menus.
@param array $items the given items. Please refer to [[Dropdown::items]] for the array structure.
@param array $parentItem the parent item information. Please refer to [[items]] for the structure of this array.
@param string $targetId the dropdown id
@return string the rendering result.
@throws \Exception
@since 2.0.1
@see http://materializecss.com/navbar.html#navbar-dropdown
|
entailment
|
public function init()
{
parent::init();
$this->clientOptions = false;
Html::addCssClass($this->options, ['widget' => 'btn']);
switch ($this->type) {
case self::TYPE_FLOATING:
case self::TYPE_FLAT:
Html::addCssClass($this->options, ['btn_type' => "btn-$this->type"]);
break;
}
switch ($this->size) {
case self::SIZE_SMALL:
case self::SIZE_LARGE:
Html::addCssClass($this->options, ['btn_size' => "btn-$this->size"]);
break;
}
// if ($this->large) {
// Html::addCssClass($this->options, ['btn_size' => 'btn-large']);
// }
if ($this->disabled) {
Html::addCssClass($this->options, ['btn_disabled' => 'disabled']);
}
}
|
Initializes the widget.
|
entailment
|
public function run()
{
if ($this->label !== false) {
$label = $this->encodeLabel ? Html::encode($this->label) : $this->label;
} else {
$label = '';
}
$content = $this->renderIcon() . $label;
return $this->tagName === 'button' ? Html::button($content, $this->options) : Html::tag($this->tagName, $content, $this->options);
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
@uses [[renderIcon]]
|
entailment
|
protected function renderIcon()
{
if (!$this->icon) {
return '';
}
return Icon::widget([
'name' => ArrayHelper::getValue($this->icon, 'name', null),
'position' => ArrayHelper::getValue($this->icon, 'position', null),
'options' => ArrayHelper::getValue($this->icon, 'options', [])
]);
}
|
Renders an icon.
@return string the rendered icon
@throws \yii\base\InvalidConfigException if icon name is not specified
@uses http://www.yiiframework.com/doc-2.0/yii-helpers-basearrayhelper.html#getValue()-detail
@see Icon::run
|
entailment
|
public function init()
{
parent::init();
$this->activateParents = true;
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getUniqueId('sidenav_');
}
Html::addCssClass($this->options, ['widget' => 'sidenav']);
if ($this->renderToggleButton) {
$this->toggleButtonOptions = ArrayHelper::merge([
'label' => false,
'icon' => [
'name' => 'menu'
],
'type' => Button::TYPE_FLAT,
], $this->toggleButtonOptions);
Html::addCssClass($this->toggleButtonOptions['options'], ['toggleButton' => 'sidenav-trigger']);
$this->toggleButtonOptions['options']['data-target'] = $this->options['id'];
}
$this->registerPlugin('Sidenav', '.sidenav');
}
|
Initializes the widget.
|
entailment
|
public function run()
{
if ($this->renderToggleButton) {
$html[] = $this->renderToggleButton();
}
$html[] = $this->renderItems();
return implode("\n", $html);
}
|
Executes the widget.
@return string
@throws \Exception
|
entailment
|
protected function renderItem($item)
{
if (is_string($item)) {
return $item;
}
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$listItemOptions = ArrayHelper::getValue($item, 'options', []);
$items = ArrayHelper::getValue($item, 'items');
$url = ArrayHelper::getValue($item, 'url', '#');
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
if (isset($item['active'])) {
$active = ArrayHelper::remove($item, 'active', false);
} else {
$active = $this->isItemActive($item);
}
if (empty($items)) {
$content = Html::a($label, $url, $linkOptions);
} else {
Html::addCssClass($listItemOptions, ['widget' => 'submenu']);
Html::addCssClass($linkOptions, ['widget' => 'submenu-opener']);
if ($this->dropDownCaret !== '') {
$label .= ' ' . $this->dropDownCaret;
}
if (is_array($items)) {
if ($this->activateItems) {
$items = $this->isChildActive($items, $active);
}
$items = $this->renderCollapsible(Html::a($label, $url, $linkOptions), $items, $active);
}
$content = $items;
}
if ($this->activateItems && $active) {
Html::addCssClass($listItemOptions, 'active');
}
return Html::tag('li', $content, $listItemOptions);
}
|
Renders a widget's item.
@param string|array $item the item to render.
@return string the rendering result.
@throws InvalidConfigException
|
entailment
|
protected function renderCollapsible($link, $items = [], $isParentActive = false)
{
$itemOptions = [];
if ($isParentActive) {
Html::addCssClass($itemOptions, ['item-activation' => 'active']);
}
$collapsibleItems = [
[
'header' => ['content' => $link],
'body' => ['content' => $this->buildCollapsibleBody($items)],
'options' => $itemOptions
],
];
return Collapsible::widget([
'items' => $collapsibleItems,
'type' => Collapsible::TYPE_ACCORDION,
]);
}
|
Renders a submenu as Collapsible in side navigation element.
@param string $link the trigger link.
@param array $items the submenu items.
@param bool $isParentActive whether the submenu's parent list element shall get an 'active' state.
@return string the Collapsible markup.
@throws \Exception
|
entailment
|
protected function buildCollapsibleBody($items = [])
{
$html[] = Html::beginTag('ul');
foreach ($items as $item) {
$url = ArrayHelper::getValue($item, 'url', null);
$label = ArrayHelper::getValue($item, 'label', '');
$options = ArrayHelper::getValue($item, 'options', []);
$link = Html::a($label, $url, $options);
$html[] = Html::tag('li', $link);
}
$html[] = Html::endTag('ul');
return implode("\n", $html);
}
|
Build the needed markup for the collapsible body, i. e. the `<ul>` containing the submenu links.
@param array $items the submenu items.
@return string the Collapsible body markup.
|
entailment
|
public function init()
{
if (!isset($this->containerOptions['class'])) {
Html::addCssClass($this->containerOptions, ['breadcrumbsContainer' => 'breadcrumbs']);
}
if (!isset($this->options['class'])) {
Html::addCssClass($this->options, ['wrapper' => 'nav-wrapper']);
}
if ($this->innerContainerOptions !== false && !isset($this->innerContainerOptions['class'])) {
Html::addCssClass($this->innerContainerOptions, ['innerContainer' => 'col s12']);
}
}
|
Initialize the widget.
|
entailment
|
public function run()
{
if (empty($this->links)) {
return '';
}
$html[] = Html::beginTag('nav', $this->containerOptions);
$html[] = Html::beginTag($this->tag, $this->options);
if ($this->innerContainerOptions !== false) {
$innerContainerTag = ArrayHelper::remove($this->innerContainerOptions, 'tag', 'div');
$html[] = Html::beginTag($innerContainerTag, $this->innerContainerOptions);
}
$html[] = implode('', $this->prepareLinks());
if ($this->innerContainerOptions !== false) {
$html[] = Html::endTag($innerContainerTag);
}
$html[] = Html::endTag($this->tag);
$html[] = Html::endTag('nav');
return implode("\n", $html);
}
|
Render the widget.
@return string the result of widget execution to be outputted.
@throws InvalidConfigException
|
entailment
|
protected function renderItem($link, $template)
{
$encodeLabel = ArrayHelper::remove($link, 'encode', $this->encodeLabels);
if (array_key_exists('label', $link)) {
$label = $encodeLabel ? Html::encode($link['label']) : $link['label'];
} else {
throw new InvalidConfigException('The "label" element is required for each link.');
}
if (isset($link['template'])) {
$template = $link['template'];
}
if (isset($link['url'])) {
$options = $link;
Html::addCssClass($options, ['link' => 'breadcrumb']);
unset($options['template'], $options['label'], $options['url']);
$link = Html::a($label, $link['url'], $options);
} else {
$link = $label;
}
return strtr($template, ['{link}' => $link]);
}
|
Renders a single breadcrumb item.
@param array $link the link to be rendered. It must contain the "label" element. The "url" element is optional.
@param string $template the template to be used to rendered the link. The token "{link}" will be replaced by the link.
@return string the rendering result
@throws InvalidConfigException if `$link` does not have "label" element.
|
entailment
|
protected function prepareLinks()
{
$links = [];
if ($this->homeLink === null) {
$links[] = $this->renderItem([
'label' => Yii::t('yii', 'Home'),
'url' => Yii::$app->homeUrl,
], $this->itemTemplate);
} elseif ($this->homeLink !== false) {
$links[] = $this->renderItem($this->homeLink, $this->itemTemplate);
}
foreach ($this->links as $link) {
if (!is_array($link)) {
$link = ['label' => $link];
}
$links[] = $this->renderItem($link, isset($link['url']) ? $this->itemTemplate : $this->activeItemTemplate);
}
return $links;
}
|
Generates all breadcrumb links and sets active states.
@return array all processed items
@uses [[renderItem]]
@throws InvalidConfigException
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->sliderOptions, ['plugin' => 'slider']);
if ($this->fullscreen === true) {
Html::addCssClass($this->sliderOptions, ['fullscreen' => 'fullscreen']);
}
$this->clientOptions['indicators'] = $this->showIndicators;
$this->clientOptions['height'] = $this->height;
$this->clientOptions['duration'] = $this->duration;
$this->clientOptions['interval'] = $this->interval;
$this->registerPlugin('Slider', '.slider');
}
|
Initialize the widget.
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);
$html[] = Html::beginTag('div', $this->sliderOptions);
$html[] = $this->renderSlides();
$html[] = Html::endTag('div');
$html[] = Html::endTag($tag);
return implode("\n", $html);
}
|
Execute the widget.
@return string the rendered markup
|
entailment
|
protected function renderSlides()
{
$slides = [];
foreach ($this->slides as $slide) {
$slides[] = $this->renderSlide($slide);
}
$html[] = Html::tag('ul', implode("\n", $slides), ['class' => 'slides']);
return implode("\n", $html);
}
|
Parses all [[slides]] and generates the slide list.
@return string the list markup
|
entailment
|
protected function renderSlide($slideConfig = [])
{
$imageOptions = ArrayHelper::getValue($slideConfig, 'image', []);
$imageSrc = ArrayHelper::remove($imageOptions, 'src', null);
if (!$imageSrc) {
return '';
}
$caption = $this->renderCaption(ArrayHelper::getValue($slideConfig, 'caption', false));
$options = ArrayHelper::getValue($slideConfig, 'options', []);
$options = ArrayHelper::merge($this->slideOptions, $options);
$html[] = Html::beginTag('li', $options);
$html[] = Html::img($imageSrc, $imageOptions);
$html[] = $caption;
$html[] = Html::endTag('li');
return implode("\n", $html);
}
|
Renders a single slide.
@param array $slideConfig the configuration for the slide
@return string the slide's markup
|
entailment
|
protected function renderCaption($captionConfig)
{
if ($captionConfig === false) {
return '';
}
$content = ArrayHelper::getValue($captionConfig, 'content', '');
$alignment = ArrayHelper::getValue($captionConfig, 'align', null);
$options = ArrayHelper::getValue($captionConfig, 'options', []);
$options = ArrayHelper::merge($this->captionOptions, $options);
Html::addCssClass($options, ['caption' => 'caption']);
if ($alignment) {
Html::addCssClass($options, ['align' => $alignment]);
}
return Html::tag('div', $content, $options);
}
|
Renders the caption markup.
@param false|array $captionConfig the caption configuration data
@return string the markup of the caption
|
entailment
|
public function init()
{
parent::init();
if ($this->useNoUiSlider) {
if (!ArrayHelper::keyExists('start', $this->clientOptions)) {
$this->clientOptions['start'] = $this->start;
}
if (!ArrayHelper::keyExists('range', $this->clientOptions)) {
$this->clientOptions['range'] = $this->range;
}
if (!ArrayHelper::keyExists('step', $this->clientOptions)) {
$this->clientOptions['step'] = $this->step;
}
if ($this->vertical) {
$this->clientOptions['orientation'] = 'vertical';
}
if (!isset($this->sliderOptions['id'])) {
$this->sliderOptions['id'] = $this->getId();
}
$this->addUpdateEvent();
$this->registerClientScripts();
}
}
|
Initialize the widget.
|
entailment
|
protected function addUpdateEvent()
{
$sliderId = $this->sliderOptions['id'];
$this->inputOptions['data-slider-target'] = $sliderId;
if (!isset($this->clientEvents['update'])) {
$this->clientEvents['update'] = new JsExpression(<<<JS
function (values, handle) {
var value = values[handle];
$('[data-slider-target="{$sliderId}"]').val(value);
}
JS
);
}
}
|
Adds default noUiSlider update event to [[clientEvents]].
@see https://refreshless.com/nouislider/events-callbacks/#section-update
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);
if (!$this->useNoUiSlider) {
$html[] = $this->renderHtml5RangeInput();
} else {
$html[] = $this->renderNoUiSlider();
}
$html[] = Html::endTag($tag);
return implode("\n", $html);
}
|
Execute the widget.
@return string the rendered markup.
|
entailment
|
protected function renderHtml5RangeInput()
{
$html[] = Html::beginTag('div', ['class' => 'range-field']);
// workaround for: https://github.com/Dogfalo/materialize/issues/5761
if (!isset($this->inputOptions['min'])) {
$this->inputOptions['min'] = 0;
}
if (!isset($this->inputOptions['max'])) {
$this->inputOptions['max'] = 100;
}
if ($this->hasModel()) {
$html[] = Html::activeInput('range', $this->model, $this->attribute, $this->inputOptions);
} else {
$html[] = Html::input('range', $this->name, $this->value, $this->inputOptions);
}
$html[] = Html::endTag('div');
return implode("\n", $html);
}
|
Renders a standard HTML5 range input field.
This is only being effective when [[$useNoUiSlider]] is set to 'false'.
@return string the field markup.
|
entailment
|
protected function renderNoUiSlider()
{
$html[] = Html::tag('div', '', $this->sliderOptions);
if ($this->renderHiddenInput) {
$html[] = $this->renderHiddenInput();
}
return implode("\n", $html);
}
|
Renders the markup for the noUiSlider plugin.
This is only being effective when [[$useNoUiSlider]] is set to 'true'.
@return string the field markup.
|
entailment
|
protected function renderHiddenInput()
{
if ($this->hasModel()) {
return Html::activeHiddenInput($this->model, $this->attribute, $this->inputOptions);
} else {
return Html::hiddenInput($this->name, $this->value, $this->inputOptions);
}
}
|
Renders a hidden input field which holds the value issued by the slider.
This is only being effective when [[$useNoUiSlider]] is set to 'true'.
@return string the input field markup.
|
entailment
|
protected function registerClientScripts()
{
$view = $this->getView();
NoUiSliderAsset::register($view);
$id = $this->sliderOptions['id'];
$varName = $this->getUniqueId('slider_');
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);
$view->registerJs(<<<JS
var $varName = document.getElementById('$id');
noUiSlider.create($varName, {$options});
JS
);
}
$this->registerClientEvents($varName);
}
|
Registers all scripts needed by the underlying JS plugin.
|
entailment
|
protected function registerClientEvents($sliderVarName = null)
{
if (!empty($this->clientEvents)) {
$js = [];
foreach ($this->clientEvents as $event => $handler) {
$js[] = "$sliderVarName.noUiSlider.on('$event', $handler);";
}
$this->getView()->registerJs(implode("\n", $js));
}
}
|
Registers the events of the slider.
@param string $sliderVarName the JS variable name of the slider element.
|
entailment
|
public function init()
{
parent::init();
if (!isset($this->options['options'])) {
$this->options['options'] = [];
}
$this->options['multiple'] = $this->multiple;
$this->parseItems();
$this->insertPlaceholder();
$this->registerPlugin('FormSelect');
}
|
Initializes the widget.
|
entailment
|
protected function insertPlaceholder()
{
$placeholder = ArrayHelper::remove($this->options, 'placeholder', $this->defaultPlaceholder);
if ($placeholder !== false) {
$this->items = ArrayHelper::merge(['' => $placeholder], $this->items);
$placeholderOption = [
'' => ['disabled' => true],
];
$this->options['options'] = ArrayHelper::merge($placeholderOption, $this->options['options']);
}
}
|
Inserts a blank option at the beginning of the options list.
To prevent this blank option to be rendered, simply set the 'placeholder' key of [[options]] to `false`.
|
entailment
|
protected function parseItems()
{
$items = $this->items;
$this->items = [];
foreach ($items as $optionValue => $item) {
$this->parseItem($optionValue, $item);
}
}
|
Parses all items.
@uses [[parseItem()]]
|
entailment
|
protected function parseItem($optionValue, $item, $parentKey = null)
{
if (is_array($item)) {
if (ArrayHelper::keyExists('options', $item)) {
$label = ArrayHelper::getValue($item, 'label');
$optionOptions = ArrayHelper::getValue($item, 'options', []);
$this->addItem($optionValue, $label, $parentKey);
$this->addItemOption($optionValue, $optionOptions);
} else { // nested values -> optgroup
foreach ($item as $subOptionValue => $subItem) {
$this->parseItem($subOptionValue, $subItem, $optionValue);
}
}
} else {
$this->addItem($optionValue, $item, $parentKey);
$this->addItemOption($optionValue, ['label' => $item]);
}
}
|
Parses a single item.
Uses recursion to determine nested value options, which will then be rendered inside <optgroups>.
Please refer to
[yii\helpers\BaseHtml::activeDropDownList()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList()-detail)
for details on `$options` and `$items`.
@param mixed $optionValue the value of the option.
@param mixed $item the current item to be parsed.
@param mixed|null $parentKey the parent option's key if a nested value is currently parsed.
|
entailment
|
private function addItem($value, $label, $parentKey = null)
{
if ($parentKey) {
$this->items[$parentKey][$value] = $label;
} else {
$this->items[$value] = $label;
}
}
|
Adds an item value and label to [[$items]].
@param mixed $value the value of the option.
@param mixed $label the label of the option.
@param mixed|null $parentKey the parent option's key if a nested value is being added.
|
entailment
|
private function addItemOption($value, $options)
{
$this->options['options'] = ArrayHelper::merge($this->options['options'], [$value => $options]);
}
|
Adds option `options` to [[$options]].
@param mixed $value the value of the option.
@param array $options the attributes for the select option tags.
@see http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList()-detail
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->options, ['widget' => 'chip']);
if ($this->imageOptions && !isset($this->imageOptions['src'])) {
throw new InvalidConfigException('The "src" attribute for the image is required.');
}
if ($this->renderIcon && !isset($this->icon['name'])) {
$this->icon['name'] = 'close';
}
}
|
Initializes the widget.
@throws InvalidConfigException if the src property ot the image is not defined
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);
if ($this->imageOptions) {
$src = ArrayHelper::remove($this->imageOptions, 'src', '');
$html[] = Html::img($src, $this->imageOptions);
}
$html[] = $this->encodeContent ? Html::encode($this->content) : $this->content;
if ($this->renderIcon) {
Html::addCssClass($this->icon['options'], ['close-trigger' => 'close']);
$html[] = Icon::widget([
'name' => ArrayHelper::getValue($this->icon, 'name', null),
'position' => ArrayHelper::getValue($this->icon, 'position', ''),
'options' => ArrayHelper::getValue($this->icon, 'options', [])
]);
}
$html[] = Html::endTag($tag);
return implode("\n", $html);
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
@throws \Exception
@uses [[Icon]]
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->carouselOptions, ['plugin' => 'carousel']);
if ($this->fullWidth) {
Html::addCssClass($this->carouselOptions, ['fullwidth' => 'carousel-slider']);
$this->clientOptions['fullWidth'] = true;
}
$this->clientOptions['noWrap'] = $this->noWrap;
$this->clientOptions['indicators'] = $this->showIndicators;
$this->clientOptions['duration'] = $this->duration;
$this->clientOptions['dist'] = $this->perspectiveZoom;
$this->clientOptions['shift'] = $this->centerSpacing;
$this->clientOptions['padding'] = $this->padding;
$this->clientOptions['numVisible'] = $this->visibleItems;
$this->registerPlugin('Carousel', '.carousel');
}
|
Initialize the widget.
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);
$html[] = Html::beginTag('div', $this->carouselOptions);
$html[] = $this->renderFixedItem();
$html[] = $this->renderItems();
$html[] = Html::endTag('div');
$html[] = Html::endTag($tag);
return implode("\n", $html);
}
|
Execute the widget.
|
entailment
|
protected function renderItems()
{
if (!$this->items) {
return '';
}
$html = [];
foreach ($this->items as $item) {
$html[] = $this->renderItem($item);
}
return implode("\n", $html);
}
|
Parses all [[items]] and renders item list.
@return string the item list markup
|
entailment
|
protected function renderItem($item = [])
{
$tag = ArrayHelper::getValue($item, 'tag', 'div');
$content = ArrayHelper::getValue($item, 'content', '');
$options = ArrayHelper::getValue($item, 'options', []);
$options = ArrayHelper::merge($this->itemOptions, $options);
Html::addCssClass($options, ['item' => 'carousel-item']);
return Html::tag($tag, $content, $options);
}
|
Renders a single carousel item.
@param array $item the item configuration
@return string the item markup
|
entailment
|
protected function renderFixedItem()
{
if ($this->fixedItemOptions === false) {
return '';
}
$tag = ArrayHelper::remove($this->fixedItemOptions, 'tag', 'div');
$content = ArrayHelper::remove($this->fixedItemOptions, 'content', '');
Html::addCssClass($this->fixedItemOptions, ['fixed-item' => 'carousel-fixed-item']);
return Html::tag($tag, $content, $this->fixedItemOptions);
}
|
Renders the optional fixed item.
@return string the fixed item's markup
|
entailment
|
public function init()
{
parent::init();
if (!isset($this->containerOptions['id'])) {
$this->containerOptions['id'] = $this->getId();
}
Html::addCssClass($this->containerOptions, ['widget-container' => 'chips-container']);
if ($this->items) {
$this->clientOptions['data'] = $this->items;
}
if ($this->autocompleteOptions) {
$this->clientOptions['autocompleteOptions'] = $this->autocompleteOptions;
}
if ($this->placeholder) {
$this->clientOptions['placeholder'] = $this->placeholder;
}
if ($this->secondaryPlaceholder) {
$this->clientOptions['secondaryPlaceholder'] = $this->secondaryPlaceholder;
}
$this->registerPlugin('Chips', "#{$this->containerOptions['id']} .chips");
}
|
Initialize the widget.
|
entailment
|
public function run()
{
$tag = ArrayHelper::remove($this->containerOptions, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->containerOptions);
if ($this->renderHiddenInput) {
$html[] = $this->renderHiddenInput();
}
$html[] = Html::beginTag('div', ['class' => 'chips']);
$html[] = Html::endTag('div');
$html[] = Html::endTag($tag);
return implode("\n", $html);
}
|
Execute the widget.
@return string the widget markup.
|
entailment
|
public function init()
{
parent::init();
if (is_array($this->pager) && !ArrayHelper::keyExists('class', $this->pager)) {
$this->pager = [
'class' => LinkPager::class,
];
}
}
|
Initializes the widget.
|
entailment
|
public function init()
{
if ($this->submenuOptions === null) {
$this->submenuOptions = $this->options;
unset($this->submenuOptions['id']);
}
parent::init();
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getUniqueId('dropdown_');
}
Html::addCssClass($this->options, ['widget' => 'dropdown-content']);
$this->registerPlugin('Dropdown', '.dropdown-trigger');
}
|
Initializes the widget.
If you override this method, make sure you call the parent implementation first.
|
entailment
|
public function run()
{
if ($this->toggleButtonOptions !== false) {
$html[] = $this->renderToggleButton();
}
$html[] = $this->renderItems($this->items, $this->options);
return implode("\n", $html);
}
|
Renders the widget and registers the plugin asset.
@return string the result of widget execution to be outputted.
@throws InvalidConfigException
@see \macgyer\yii2materializecss\lib\MaterializeWidgetTrait|MaterializeWidgetTrait
|
entailment
|
protected function renderToggleButton()
{
if (!isset($this->toggleButtonOptions['options']['data-target'])) {
$this->toggleButtonOptions['options']['data-target'] = $this->options['id'];
}
Html::addCssClass($this->toggleButtonOptions['options'], ['toggle-button' => 'dropdown-trigger']);
return Button::widget($this->toggleButtonOptions);
}
|
Renders the dropdown toggle button.
@return string the markup of the toggle button.
@throws \Exception
|
entailment
|
public function init()
{
parent::init();
$this->initDefaults();
$options = $this->options;
$html = $this->renderToggleButton();
$tag = ArrayHelper::remove($options, 'tag', 'div');
$html .= Html::beginTag($tag, $options);
if ($this->closeButtonPosition === self::CLOSE_BUTTON_POSITION_PRECEDE_CONTENT_CONTAINER) {
$html .= $this->renderCloseButton();
}
$html .= Html::beginTag('div', ['class' => 'modal-content']);
if ($this->closeButtonPosition === self::CLOSE_BUTTON_POSITION_BEFORE_CONTENT) {
$html .= $this->renderCloseButton();
}
echo $html;
$this->registerPlugin('Modal');
}
|
Initializes the widget.
@uses [[renderCloseButton()]]
@uses [[registerPlugin()]]
|
entailment
|
public function run()
{
$options = $this->options;
$html = '';
if ($this->closeButtonPosition === self::CLOSE_BUTTON_POSITION_AFTER_CONTENT) {
$html = $this->renderCloseButton();
}
$html .= Html::endTag('div');
$html .= $this->renderFooter();
if ($this->closeButtonPosition === self::CLOSE_BUTTON_POSITION_SUCCEED_CONTENT_CONTAINER) {
$html .= $this->renderCloseButton();
}
$tag = ArrayHelper::remove($options, 'tag', 'div');
$html .= Html::endTag($tag);
echo $html;
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
@uses [[renderCloseButton()]]
|
entailment
|
protected function renderFooter()
{
if (!$this->footer &&
$this->closeButtonPosition != self::CLOSE_BUTTON_POSITION_BEFORE_FOOTER &&
$this->closeButtonPosition != self::CLOSE_BUTTON_POSITION_AFTER_FOOTER) {
return '';
}
$html = [];
Html::addCssClass($this->footerOptions, ['footer' => 'modal-footer']);
$html[] = Html::beginTag('div', $this->footerOptions);
if ($this->closeButtonPosition === self::CLOSE_BUTTON_POSITION_BEFORE_FOOTER) {
$html[] = $this->renderCloseButton();
}
$html[] = $this->footer;
if ($this->closeButtonPosition === self::CLOSE_BUTTON_POSITION_AFTER_FOOTER) {
$html[] = $this->renderCloseButton();
}
$html[] = Html::endTag('div');
return implode("\n", $html);
}
|
Renders the Modal footer.
@return string the rendered markup of the footer.
@uses [[renderCloseButton()]]
|
entailment
|
protected function initDefaults()
{
switch ($this->modalType) {
case self::TYPE_FIXED_FOOTER:
Html::addCssClass($this->options, ['modalType' => 'modal-fixed-footer']);
break;
case self::TYPE_BOTTOM_SHEET:
Html::addCssClass($this->options, ['modalType' => 'bottom-sheet']);
break;
default:
break;
}
Html::addCssClass($this->options, ['widget' => 'modal']);
if ($this->closeButton !== false) {
$this->closeButton = ArrayHelper::merge([
'class' => 'modal-close',
], $this->closeButton);
}
if ($this->toggleButton !== false) {
$this->toggleButton = ArrayHelper::merge([
'class' => 'modal-trigger btn',
], $this->toggleButton);
}
$this->clientOptions['opacity'] = $this->overlayOpacity;
$this->clientOptions['inDuration'] = $this->inDuration;
$this->clientOptions['outDuration'] = $this->outDuration;
$this->clientOptions['preventScrolling'] = $this->preventScrolling;
$this->clientOptions['dismissible'] = $this->dismissible;
$this->clientOptions['startingTop'] = $this->startingTopOffset;
$this->clientOptions['endingTop'] = $this->endingTopOffset;
}
|
Set inital default options.
|
entailment
|
private static function normalizeMaxLength($model, $attribute, &$options)
{
if (isset($options['maxlength']) && $options['maxlength'] === true) {
unset($options['maxlength']);
$showCharacterCounter = ArrayHelper::remove($options, 'showCharacterCounter', false);
$attrName = static::getAttributeName($attribute);
foreach ($model->getActiveValidators($attrName) as $validator) {
if ($validator instanceof StringValidator && $validator->max !== null) {
$options['maxlength'] = $validator->max;
if ($showCharacterCounter === true) {
$options['data-length'] = $validator->max;
}
break;
}
}
}
}
|
If `maxlength` option is set true and the model attribute is validated by a string validator,
the `maxlength` option will take the value of [\yii\validators\StringValidator::max](http://www.yiiframework.com/doc-2.0/yii-validators-stringvalidator.html#$max-detail). Additionally the
`length` property is populated with the same value, to enable the Materialize character counter.
@param Model $model the model object
@param string $attribute the attribute name or expression.
@param array $options the tag options in terms of name-value pairs.
@see http://materializecss.com/forms.html#character-counter
|
entailment
|
public static function radioList($name, $selection = null, $items = [], $options = [])
{
if (ArrayHelper::isTraversable($selection)) {
$selection = array_map('strval', (array)$selection);
}
$formatter = ArrayHelper::remove($options, 'item');
$itemOptions = ArrayHelper::remove($options, 'itemOptions', []);
$encode = ArrayHelper::remove($options, 'encode', true);
$separator = ArrayHelper::remove($options, 'separator', "\n");
$tag = ArrayHelper::remove($options, 'tag', 'div');
// add a hidden field so that if the list box has no option being selected, it still submits a value
$hidden = isset($options['unselect']) ? static::hiddenInput($name, $options['unselect']) : '';
unset($options['unselect']);
$lines = [];
$index = 0;
foreach ($items as $value => $label) {
$checked = $selection !== null &&
(!ArrayHelper::isTraversable($selection) && !strcmp($value, $selection)
|| ArrayHelper::isTraversable($selection) && ArrayHelper::isIn((string)$value, $selection));
if ($formatter !== null) {
$lines[] = call_user_func($formatter, $index, $label, $name, $checked, $value);
} else {
$lines[] = Html::tag('div', static::radio($name, $checked, array_merge($itemOptions, [
'value' => $value,
'label' => $encode ? static::encode($label) : $label,
])));
}
$index++;
}
$visibleContent = implode($separator, $lines);
if ($tag === false) {
return $hidden . $visibleContent;
}
return $hidden . static::tag($tag, $visibleContent, $options);
}
|
Generates a list of radio buttons.
A radio button list is like a checkbox list, except that it only allows single selection.
@param string $name the name attribute of each radio button.
@param string|array|null $selection the selected value(s). String for single or array for multiple selection(s).
@param array $items the data item used to generate the radio buttons.
The array keys are the radio button values, while the array values are the corresponding labels.
@param array $options options (name => config) for the radio button list container tag.
The following options are specially handled:
- tag: string|false, the tag name of the container element. False to render radio buttons without container.
See also [\yii\helpers\Html::tag()](https://www.yiiframework.com/doc/api/2.0/yii-helpers-basehtml#tag()-detail).
- unselect: string, the value that should be submitted when none of the radio buttons is selected.
By setting this option, a hidden input will be generated.
- encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true.
This option is ignored if `item` option is set.
- separator: string, the HTML code that separates items.
- itemOptions: array, the options for generating the radio button tag using [[radio()]].
- item: callable, a callback that can be used to customize the generation of the HTML code
corresponding to a single item in $items. The signature of this callback must be:
```php
function ($index, $label, $name, $checked, $value)
```
where $index is the zero-based index of the radio button in the whole list; $label
is the label for the radio button; and $name, $value and $checked represent the name,
value and the checked status of the radio button input, respectively.
See [\yii\helpers\Html::renderTagAttributes()](https://www.yiiframework.com/doc/api/2.0/yii-helpers-basehtml#renderTagAttributes()-detail) for details on how attributes are being rendered.
@return string the generated radio button list
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->options, ['widget' => 'preloader-wrapper active']);
Html::addCssClass($this->spinnerOptions, ['spinner' => 'spinner-layer']);
switch ($this->size) {
case self::SIZE_SMALL:
Html::addCssClass($this->options, ['spinner-size' => 'small']);
break;
case self::SIZE_BIG:
Html::addCssClass($this->options, ['spinner-size' => 'big']);
break;
}
if ($this->flashColors === false && $this->color) {
$color = ArrayHelper::getValue($this->colors, $this->color);
Html::addCssClass($this->spinnerOptions, ['spinner-color' => "spinner-$color-only"]);
}
}
|
Initializes the widget.
|
entailment
|
public function run()
{
$html[] = Html::beginTag('div', $this->options);
if ($this->flashColors !== false) {
foreach ($this->colors as $color) {
Html::addCssClass($this->spinnerOptions, ['color' => 'spinner-' . $color]);
$html[] = Html::beginTag('div', $this->spinnerOptions);
$html[] = $this->renderSpinner();
$html[] = Html::endTag('div');
Html::removeCssClass($this->spinnerOptions, ['color' => 'spinner-' . $color]);
}
} else {
$html[] = Html::beginTag('div', $this->spinnerOptions);
$html[] = $this->renderSpinner();
$html[] = Html::endTag('div');
}
$html[] = Html::endTag('div');
return implode("\n", $html);
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
@uses [[renderSpinner()]]
|
entailment
|
public function init()
{
parent::init();
if (!$this->imageSrc) {
$imageSrc = ArrayHelper::remove($this->imageOptions, 'src', null);
if (!$imageSrc) {
throw new InvalidConfigException("Image src must be defined.");
}
$this->imageSrc = $imageSrc;
}
Html::addCssClass($this->imageOptions, ['plugin' => 'materialboxed']);
if ($this->imageCaption !== false) {
$this->imageOptions['data-caption'] = $this->encodeImageCaption ? Html::encode($this->imageCaption) : $this->imageCaption;
}
}
|
Initialize the widget.
@throws InvalidConfigException
|
entailment
|
public function run()
{
$this->registerPlugin('Materialbox', '.materialboxed');
$tag = ArrayHelper::remove($this->options, 'tag', 'div');
$html[] = Html::beginTag($tag, $this->options);
$html[] = Html::img($this->imageSrc, $this->imageOptions);
$html[] = Html::endTag($tag);
return implode("\n", $html);
}
|
Execute the widget.
@return string the widget's markup.
|
entailment
|
public function init()
{
parent::init();
$this->alertLevels = ArrayHelper::merge($this->predefinedAlertLevels, $this->alertLevels);
}
|
Initializes the widget.
@uses [yii\helper\BaseArrayHelper::merge()](http://www.yiiframework.com/doc-2.0/yii-helpers-basearrayhelper.html#merge()-detail)
|
entailment
|
public function run()
{
$flashes = Yii::$app->session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $data) {
if (isset($this->alertLevels[$type])) {
$data = (array) $data;
foreach ($data as $i => $message) {
/* initialize css class for each alert box */
$this->options['class'] = 'alert ' . $this->alertLevels[$type] . $appendCss;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
echo $this->renderHtml($message, $this->options);
}
Yii::$app->session->removeFlash($type);
}
}
}
|
Executes the widget.
@uses [yii\web\Session](http://www.yiiframework.com/doc-2.0/yii-web-session.html)
|
entailment
|
private function renderHtml($message, $options = [])
{
$html = Html::beginTag('div', $options);
$html .= '<div class="card-panel">';
$html .= $message;
$html .= '</div>';
$html .= Html::endTag('div');
return $html;
}
|
Renders a single flash message.
@param string $message the content of the message
@param array $options the HTML attributes for the container tag
@return string
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->options, ['widget' => 'collapsible']);
if ($this->isPopoutStyle) {
Html::addCssClass($this->options, ['popout' => 'popout']);
}
if ($this->type == self::TYPE_EXPANDABLE) {
$this->clientOptions['accordion'] = false;
}
$this->registerPlugin('Collapsible');
}
|
Initialize the widget.
|
entailment
|
protected function renderItem($item = [])
{
$itemOptions = ArrayHelper::getValue($item, 'options', []);
$headerOptions = ArrayHelper::getValue($item, 'header', []);
$headerContent = ArrayHelper::remove($headerOptions, 'content');
$headerTag = ArrayHelper::remove($headerOptions, 'tag', 'div');
$bodyOptions = ArrayHelper::getValue($item, 'body', []);
$bodyContent = ArrayHelper::remove($bodyOptions, 'content', []);
$bodyTag = ArrayHelper::remove($bodyOptions, 'tag', 'div');
if (!$headerContent && !$bodyContent) {
return '';
}
$html[] = Html::beginTag('li', $itemOptions);
if ($headerContent) {
Html::addCssClass($headerOptions, ['header' => 'collapsible-header']);
$html[] = Html::tag($headerTag, $headerContent, $headerOptions);
}
if ($bodyContent) {
Html::addCssClass($bodyOptions, ['body' => 'collapsible-body']);
$html[] = Html::tag($bodyTag, $bodyContent, $bodyOptions);
}
$html[] = Html::endTag('li');
return implode("\n", $html);
}
|
Render a single item.
@param array $item the item configuration
@return string the item's markup
|
entailment
|
public function init()
{
parent::init();
Html::addCssClass($this->options, ['widget' => 'fixed-action-btn']);
Html::addCssClass($this->buttonOptions, ['widget' => 'btn-floating']);
if ($this->clickToToggle) {
$this->clientOptions['hoverEnabled'] = false;
}
if ($this->horizontal) {
$this->clientOptions['direction'] = 'left';
Html::addCssClass($this->options, ['containerLayout' => 'horizontal']);
}
if ($this->toolbar) {
$this->clientOptions['toolbarEnabled'] = true;
Html::addCssClass($this->options, ['toolbar' => 'toolbar']);
}
$this->registerPlugin('FloatingActionButton');
}
|
Initializes the widget.
|
entailment
|
public function run()
{
$html[] = Html::beginTag('div', $this->options);
// Visible button
$html[] = Button::widget([
'tagName' => $this->buttonTagName,
'label' => $this->buttonLabel,
'encodeLabel' => $this->buttonEncodeLabel,
'options' => $this->buttonOptions,
'icon' => $this->buttonIcon
]);
$html[] = $this->renderItems();
$html[] = Html::endTag('div');
return implode("\n", $html);
}
|
Executes the widget.
@return string the result of widget execution to be outputted.
@throws InvalidConfigException
@throws \Exception
@see Button|Button
|
entailment
|
protected function renderItems()
{
$elements = [];
$items = $this->items;
foreach ($items as $item) {
if (isset($item['visible']) && !$item['visible']) {
continue;
}
if (is_string($item)) {
$elements[] = $item;
continue;
}
if (!array_key_exists('label', $item)) {
throw new InvalidConfigException("The 'label' option is required.");
}
$encodeLabel = isset($item['encodeLabel']) ? $item['encodeLabel'] : $this->encodeLabels;
$label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
$itemOptions = ArrayHelper::getValue($item, 'options', []);
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
Html::addCssClass($linkOptions, ['link' => 'btn-floating']);
$url = array_key_exists('url', $item) ? $item['url'] : '#';
$content = Html::a($label, $url, $linkOptions);
$elements[] = Html::tag('li', $content, $itemOptions);
}
return Html::tag('ul', implode("\n", $elements), $this->itemsContainerOptions);
}
|
Renders a list representing the single button items.
@return string
@throws InvalidConfigException
|
entailment
|
public function init()
{
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
if (!isset($this->options['data-success-class'])) {
$this->options['data-success-class'] = $this->successCssClass;
}
if (!isset($this->options['data-error-class'])) {
$this->options['data-error-class'] = $this->errorCssClass;
}
if ($this->enableClientValidation) {
$this->registerAfterValidateHandler();
}
parent::init();
}
|
Initialize the widget.
|
entailment
|
public function init()
{
parent::init();
$html = [];
if (empty($this->options['role'])) {
$this->options['role'] = 'navigation';
}
if ($this->fixed) {
Html::addCssClass($this->fixedContainerOptions, 'navbar-fixed');
$html[] = Html::beginTag('div', $this->fixedContainerOptions);
}
$html[] = Html::beginTag('nav', $this->options);
Html::addCssClass($this->wrapperOptions, 'nav-wrapper');
$html[] = Html::beginTag('div', $this->wrapperOptions);
if ($this->brandLabel !== false) {
Html::addCssClass($this->brandOptions, ['widget' => 'brand-logo']);
$html[] = Html::a($this->brandLabel, $this->brandUrl === false ? Yii::$app->homeUrl : $this->brandUrl, $this->brandOptions);
}
if (!isset($this->containerOptions['id'])) {
$this->containerOptions['id'] = "{$this->id}-collapse";
}
$html[] = Html::beginTag('div', $this->containerOptions);
echo implode("\n", $html);
}
|
Initializes the widget.
|
entailment
|
public function run()
{
if ($this->renderSidenav) {
$sidenavId = $this->getUniqueId('sidenav_');
$this->initSidenav($sidenavId);
}
$html = [];
$html[] = Html::endTag('div'); // container
if ($this->renderSidenav) {
$html[] = $this->renderSidenavToggleButton();
}
$html[] = Html::endTag('div'); // nav-wrapper
$html[] = Html::endTag('nav');
if ($this->fixed) {
$html[] = Html::endTag('div');
}
if ($this->renderSidenav) {
$html[] = $this->renderSidenav($sidenavId);
}
return implode("\n", $html);
}
|
Renders the widget.
|
entailment
|
protected function initSidenav($sidenavId)
{
$this->sidenavToggleButtonOptions = ArrayHelper::merge([
'label' => false,
'icon' => [
'name' => 'menu'
],
'type' => Button::TYPE_FLAT,
], $this->sidenavToggleButtonOptions);
if (!isset($this->sidenavToggleButtonOptions['options']['data-target'])) {
$this->sidenavToggleButtonOptions['options']['data-target'] = $sidenavId;
}
Html::addCssClass($this->sidenavToggleButtonOptions['options'], ['trigger' => 'sidenav-trigger']);
}
|
Initializes the side nav options.
@param string $sidenavId the side nav element's HTML id attribute.
|
entailment
|
protected function renderSidenav($sidenavId)
{
return SideNav::widget([
'items' => $this->sidenavItems,
'renderToggleButton' => false,
'clientOptions' => $this->sidenavClientOptions,
'options' => ['id' => $sidenavId],
]);
}
|
Renders the side navigation and corresponding toggle button.
@param $sidenavId
@return string the rendered side navigation markup.
@throws \Exception
|
entailment
|
public static function resolveAliases(array $parameters, array $aliases)
{
if ( !isset($parameters['alias']) ) {
return $parameters;
}
$browser_alias = $parameters['alias'];
unset($parameters['alias']);
if ( isset($aliases[$browser_alias]) ) {
$candidate_params = self::arrayMergeRecursive($aliases[$browser_alias], $parameters);
return self::resolveAliases($candidate_params, $aliases);
}
throw new \InvalidArgumentException(sprintf('Unable to resolve "%s" browser alias', $browser_alias));
}
|
Resolves browser alias into corresponding browser configuration.
@param array $parameters Browser configuration.
@param array $aliases Browser configuration aliases.
@return array
@throws \InvalidArgumentException When unable to resolve used browser alias.
|
entailment
|
public function setup(array $parameters)
{
$parameters = $this->prepareParameters($parameters);
// Make sure, that 'driver' parameter is handled first.
if ( isset($parameters['driver']) ) {
$this->setDriver($parameters['driver']);
unset($parameters['driver']);
}
foreach ( $parameters as $name => $value ) {
$method = 'set' . ucfirst($name);
if ( !method_exists($this, $method) ) {
throw new \InvalidArgumentException('Unable to set unknown parameter "' . $name . '"');
}
$this->$method($value);
}
return $this;
}
|
Initializes a browser with given configuration.
@param array $parameters Browser configuration parameters.
@return self
@throws \InvalidArgumentException When unknown parameter is discovered.
|
entailment
|
protected function prepareParameters(array $parameters)
{
return array_merge($this->_parameters, self::resolveAliases($parameters, $this->aliases));
}
|
Merges together default, given parameter and resolves aliases along the way.
@param array $parameters Browser configuration parameters.
@return array
|
entailment
|
public function setDriver($driver_name)
{
if ( !is_string($driver_name) ) {
throw new \InvalidArgumentException('The Mink driver name must be a string');
}
$this->_driverFactory = $this->_driverFactoryRegistry->get($driver_name);
$this->_mergedDefaults = self::arrayMergeRecursive($this->defaults, $this->_driverFactory->getDriverDefaults());
return $this->setParameter('driver', $driver_name);
}
|
Sets Mink driver to browser configuration.
@param string $driver_name Mink driver name.
@return self
@throws \InvalidArgumentException When Mink driver name is not a string.
|
entailment
|
protected function setParameter($name, $value)
{
if ( !isset($this->_driverFactory) ) {
throw new \LogicException('Please set "driver" parameter first.');
}
$this->_parameters[$name] = $value;
return $this;
}
|
Sets parameter.
@param string $name Parameter name.
@param mixed $value Parameter value.
@return self
@throws \LogicException When driver wasn't set upfront.
|
entailment
|
protected function getParameter($name)
{
$merged = self::arrayMergeRecursive($this->_mergedDefaults, $this->_parameters);
if ( array_key_exists($name, $merged) ) {
return $merged[$name];
}
throw new \InvalidArgumentException('Unable to get unknown parameter "' . $name . '"');
}
|
Returns parameter value.
@param string $name Name.
@return mixed
@throws \InvalidArgumentException When unknown parameter was requested.
|
entailment
|
public function createDriver()
{
$factory = $this->_driverFactoryRegistry->get($this->getDriver());
return $factory->createDriver($this);
}
|
Creates driver based on browser configuration.
@return DriverInterface
|
entailment
|
public function getSessionStrategyHash()
{
$ret = $this->getChecksum();
if ( $this->isShared() ) {
$ret .= '::' . get_class($this->getTestCase());
}
return $ret;
}
|
Returns session strategy hash based on given test case and current browser configuration.
@return string
|
entailment
|
protected static function arrayMergeRecursive($array1, $array2)
{
if ( !is_array($array1) || !is_array($array2) ) {
return $array2;
}
foreach ( $array2 as $array2_key => $array2_value ) {
if ( isset($array1[$array2_key]) ) {
$array1[$array2_key] = self::arrayMergeRecursive($array1[$array2_key], $array2_value);
}
else {
$array1[$array2_key] = $array2_value;
}
}
return $array1;
}
|
Similar to array_merge_recursive but keyed-valued are always overwritten.
Priority goes to the 2nd array.
@param mixed $array1 First array.
@param mixed $array2 Second array.
@return array
|
entailment
|
public function createStrategy($strategy_type)
{
if ( $strategy_type == ISessionStrategyFactory::TYPE_ISOLATED ) {
return $this->application->getObject('isolated_session_strategy');
}
elseif ( $strategy_type == ISessionStrategyFactory::TYPE_SHARED ) {
return $this->application->getObject('shared_session_strategy');
}
throw new \InvalidArgumentException('Incorrect session strategy type');
}
|
Creates specified session strategy.
@param string $strategy_type Session strategy type.
@return ISessionStrategy
@throws \InvalidArgumentException When session strategy type is invalid.
|
entailment
|
public function offsetSet($id, $value)
{
if ( isset($this->frozen[$id]) ) {
throw new \RuntimeException(sprintf('Cannot override frozen service "%s".', $id));
}
$this->values[$id] = $value;
$this->keys[$id] = true;
}
|
Sets a parameter or an object.
Objects must be defined as Closures.
Allowing any PHP callable leads to difficult to debug problems
as function names (strings) are callable (creating a function with
the same name as an existing parameter would break your container).
@param string $id The unique identifier for the parameter or object.
@param mixed $value The value of the parameter or a closure to define an object.
@return void
@throws \RuntimeException Prevent override of a frozen service.
|
entailment
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.