Renders button.
@param string $name button name.
@param mixed $model
@param string $key
@param integer $index
@return string rendered HTML
@throws InvalidConfigException on invalid button format.
557347
protected function renderButton($name, $model, $key, $index)
    {
        if (!isset($this->buttons[$name])) {
            return '';
        }
        $button = $this->buttons[$name];

        if ($button instanceof \Closure) {
            $url = $this->createUrl($name, $model, $key, $index);
            return call_user_func($button, $url, $model, $key);
        }
        if (!is_array($button)) {
            throw new InvalidConfigException("Button should be either a Closure or array configuration.");
        }

        // Visibility :
        if (isset($button['visible'])) {
            if ($button['visible'] instanceof \Closure) {
                if (!call_user_func($button['visible'], $model, $key, $index)) {
                    return '';
                }
            } elseif (!$button['visible']) {
                return '';
            }
        }

        // URL :
        if (isset($button['url'])) {
            $url = call_user_func($button['url'], $name, $model, $key, $index);
        } else {
            $url = $this->createUrl($name, $model, $key, $index);
        }

        // label :
        if (isset($button['label'])) {
            $label = $button['label'];

            if (isset($button['encode'])) {
                $encodeLabel = $button['encode'];
                unset($button['encode']);
            } else {
                $encodeLabel = true;
            }
            if ($encodeLabel) {
                $label = Html::encode($label);
            }
        } else {
            $label = '';
        }

        // icon :
        if (isset($button['icon'])) {
            $icon = $button['icon'];
            $label = Html::icon($icon) . (empty($label) ? '' : ' ' . $label);
        }

        $options = array_merge(ArrayHelper::getValue($button, 'options', []), $this->buttonOptions);

        return Html::a($label, $url, $options);
    }
485644
protected function includeByName( $name, $model )
    {

        $functionName = sprintf( 'include%s', ucfirst( $name ) );

        if ( ! method_exists( static::class, $functionName ) ) {
            throw new \Exception(sprintf( 'The function name "%s" does not exists on %s', $functionName, static::class ));
        }

        return $this->{$functionName}( $model );

    }
28358
private function _format($name, $result, $model)
    {
        static $view = null;

        if (!isset($this->_options[$name])) {
            $this->_options[$name] = $model->get($name, array('default', 'multiOptions', 'formatFunction', 'dateFormat', 'storageFormat', 'itemDisplay'));
        }

        $options = $this->_options[$name];

        foreach($options as $key => $value) {
            switch ($key) {
                case 'default':
                    if (is_null($result)) {
                        $result = $value;
                    }
                    break;

                case 'multiOptions':
                    $multiOptions = $value;
                    if (is_array($multiOptions)) {
                        /*
                         *  Sometimes a field is an array and will be formatted later on using the
                         *  formatFunction -> handle each element in the array.
                         */
                        if (is_array($result)) {
                            foreach($result as $key => $value) {
                                if (array_key_exists($value, $multiOptions)) {
                                    $result[$key] = $multiOptions[$value];
                                }
                            }
                        } else {
                            if (array_key_exists($result, $multiOptions)) {
                                $result = $multiOptions[$result];
                            }
                        }
                    }
                    break;

                case 'formatFunction':
                    $callback = $value;
                    $result = call_user_func($callback, $result);
                    break;

                case 'dateFormat':
                    if (array_key_exists('formatFunction', $options)) {
                        // if there is a formatFunction skip the date formatting
                        continue;
                    }

                    $dateFormat = $value;
                    $storageFormat = $model->get($name, 'storageFormat');
                    $result = \MUtil_Date::format($result, $dateFormat, $storageFormat);
                    break;

                case 'itemDisplay':
                    $function = $value;
                    if (is_callable($function)) {
                        $result = call_user_func($function, $result);
                    } elseif (is_object($function)) {
                        if (($function instanceof \MUtil_Html_ElementInterface)
                            || method_exists($function, 'append')) {
                            $object = clone $function;
                            $result = $object->append($result);
                        }
                    } elseif (is_string($function)) {
                        // Assume it is a html tag when a string
                        $result = \MUtil_Html::create($function, $result);
                    }

                default:
                    break;
            }
        }

        if (is_object($result)) {
            // If it is Lazy, execute it
            if ($result instanceof \MUtil_Lazy_LazyInterface) {
                $result = \MUtil_Lazy::rise($result);
            }

            // If it is Html, render it
            if ($result instanceof \MUtil_Html_HtmlInterface) {

                if (is_null($view)) {
                    $viewRenderer = \Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
                    if (null === $viewRenderer->view) {
                        $viewRenderer->initView();
                    }
                    $view = $viewRenderer->view;
                }

                $result = $result->render($view);
            }
        }
        return $result;
     }
769226
protected function renderDefault($name, $value, $options)
    {
        $type = $this->type;

        if (method_exists('yii\helpers\Html', $type)) {
            $options['tabindex'] = self::TABINDEX;

            if ($this->renderer->isBootstrapTheme()) {
                Html::addCssClass($options, 'form-control');
            }

            $input = Html::$type($name, $value, $options);
        } elseif (class_exists($type) && method_exists($type, 'widget')) {
            $input = $this->renderWidget($type, $name, $value, $options);
        } else {
            throw new InvalidConfigException("Invalid column type '$type'");
        }

        return $input;
    }
152140
public function addButton(string $name): void
    {
        $options = $this->formOptions['fields'][$name];

        $button = HtmlTag::createElement('button')
            ->set('id', $name)
            ->set('type', $options['type'] ?? 'button')
            ->text($options['text'] ?? '');

        if (isset($options['text'])) {
            unset($options['text']);
        }

        foreach ($options as $attr => $value) {
            $button->set($attr, $value);
        }

        echo $button;
    }
213519
public function beginForm(string $name, string $action): void
    {
        $this->formOptions = $this->getFormOptions($name);

        $form = "<form id=\"{$name}\" action=\"{$action}\" method=\"post\"";

        $usePjax = (isset($this->formOptions['use_pjax'])) ?
            filter_var($this->formOptions['use_pjax'], FILTER_VALIDATE_BOOLEAN)
            : true;

        $pjaxAttr = ($usePjax) ? 'data-pjax' : '';

        foreach ($this->formOptions as $attr => $value) {
            if (in_array($attr, ['use_pjax', 'use_csrf', 'fields'])) {
                continue;
            }

            $form .= " {$attr}=\"{$value}\"";
        }

        echo "$form $pjaxAttr>";
    }
210475
public function addActionCallback($key, $name, $callback = null)
	{
		$this->addActionCheck($key);

		$params = ['__id' => $this->primary_key];

		$this->actions[$key] = $action = new Column\ActionCallback($this, $key, $name, $params);

		if ($callback) {
			if (!is_callable($callback)) {
				throw new DataGridException('ActionCallback callback has to be callable.');
			}

			$action->onClick[] = $callback;
		}

		return $action;
	}
919347
public function addRenderer($index, $method = null)
    {
        $this->renderers[$index] = is_null($method) ?  $index : $method;
        return $this;
    }
5220
protected function renderWithJavascriptCallback($chartOption, $name)
    {
        $result = "";

        if (gettype($chartOption) === 'array') {
            $result .= $this->renderArrayWithCallback($chartOption, $name);
        }

        if (gettype($chartOption) === 'object') {
            $result .= $this->renderObjectWithCallback($chartOption, $name);
        }

        return $result;
    }
854590
public function renderContent($id, $name) {

		if ($this->hasModel()) {
			if ($this->form) {
				echo $this->form->hiddenField($this->model, $this->attribute);
			} else {
				echo CHtml::activeHiddenField($this->model, $this->attribute);
			}

		} else {
			echo CHtml::hiddenField($name, $this->value);
		}

		$this->htmlOptions['id'] = 'tags_'.$id;
		if(isset($this->htmlOptions['class']) && !empty($this->htmlOptions['class']))
			$this->htmlOptions['class'] .= ' tag-list';
		else
			$this->htmlOptions['class'] = 'tag-list';
		
		echo CHtml::openTag('div', $this->htmlOptions);
		echo "<div class='tags'></div>";
		echo CHtml::closeTag('div');
	}
814166
public function renderCellContent($column, $index, $columnIndex = null)
    {
        $id = $column->getElementId($index);
        $name = $column->getElementName($index);

        /**
         * This class inherits iconMap from BaseRenderer
         * If the input to be rendered is a drag column, we give it the appropriate icon class
         * via the $options array
         */
        $options = ['id' => $id];
        if (substr($id, -4) === 'drag') {
            $options = ArrayHelper::merge($options, ['class' => $this->iconMap['drag-handle']]);
        }
        $input = $column->renderInput($name, $options, [
            'id' => $id,
            'name' => $name,
            'indexPlaceholder' => $this->getIndexPlaceholder(),
            'index' => $index,
            'columnIndex' => $columnIndex,
            'context' => $this->context,
        ]);

        if ($column->isHiddenInput()) {
            return $input;
        }

        $layoutConfig = array_merge([
            'offsetClass' => $this->isBootstrapTheme() ? 'col-sm-offset-3' : '',
            'labelClass' => $this->isBootstrapTheme() ? 'col-sm-3' : '',
            'wrapperClass' => $this->isBootstrapTheme() ? 'col-sm-6' : '',
            'errorClass' => $this->isBootstrapTheme() ? 'col-sm-offset-3 col-sm-6' : '',
        ], $this->layoutConfig);

        Html::addCssClass($column->errorOptions, $layoutConfig['errorClass']);

        $hasError = false;
        $error = '';

        if ($index !== null) {
            $error = $column->getFirstError($index);
            $hasError = !empty($error);
        }

        $wrapperOptions = [];

        if ($hasError) {
            Html::addCssClass($wrapperOptions, 'has-error');
        }

        Html::addCssClass($wrapperOptions, $layoutConfig['wrapperClass']);

        $options = [
            'class' => "field-$id list-cell__$column->name" . ($hasError ? ' has-error' : '')
        ];

        if ($this->isBootstrapTheme()) {
            Html::addCssClass($options, 'form-group');
        }

        if (is_callable($column->columnOptions)) {
            $columnOptions = call_user_func($column->columnOptions, $column->getModel(), $index, $this->context);
        } else {
            $columnOptions = $column->columnOptions;
        }

        $options = array_merge_recursive($options, $columnOptions);

        $content = Html::beginTag('div', $options);

        if (empty($column->title)) {
            Html::addCssClass($wrapperOptions, $layoutConfig['offsetClass']);
        } else {
            $labelOptions = ['class' => $layoutConfig['labelClass']];
            if ($this->isBootstrapTheme()) {
                Html::addCssClass($labelOptions, 'control-label');
            }

            $content .= Html::label($column->title, $id, $labelOptions);
        }

        $content .= Html::tag('div', $input, $wrapperOptions);

        // first line
        if ($columnIndex == 0) {
            if ($this->max !== $this->min) {
                $content .= $this->renderActionColumn($index);
            }
            if ($this->cloneButton) {
                $content .= $this->renderCloneColumn();
            }
        }

        if ($column->enableError) {
            $content .= "\n" . $column->renderError($error);
        }

        $content .= Html::endTag('div');

        return $content;
    }
1328884
private function setFromEloquent($model, string $name, string $key)
    {
        $options = $model->pluck($name, $key);

        $this->set('options', $options);

        $this->addBeforeRender(function () {
            $value = [];

            collect($this->get('value'))->each(function ($item) use (&$value) {
                if (is_object($item)) {
                    $value[$item->id] = $item->name;
                } else {
                    $value[] = $item;
                }
            });

            $this->set('value', $value);
        });

        return $this;
    }
768126
protected function updateNormalizers(Index $index, string $name)
    {
        $settings = $index->getSettings();
        $customNormalizers = $this->getCustomNormalizers();
        $missingNormalizers = [];

        try {
            foreach ($customNormalizers as $id => $normalizer) {
                if (!$settings->get("analysis.normalizer.{$id}")) {
                    $missingNormalizers[$id] = $normalizer;
                }
            }
        } catch (\Throwable $e) {
            $this->logger->error(
                sprintf('Unable to read index [%s] and get normalizer settings.', $name),
                ['exception' => $e, 'index_name' => $name]
            );

            return;
        }

        if (empty($missingNormalizers)) {
            $this->logger->info(
                sprintf(
                    'Index [%s] has all custom normalizers [%s].',
                    $name,
                    implode(',', array_keys($customNormalizers))
                )
            );

            return;
        }

        $this->logger->warning(
            sprintf(
                'Closing index [%s] to add custom normalizers [%s].',
                $name,
                implode(',', array_keys($missingNormalizers))
            )
        );

        try {
            $index->close();
            $index->setSettings(['analysis' => ['normalizer' => $missingNormalizers]]);
            $index->open();
        } catch (\Throwable $e) {
            $this->logger->error(
                sprintf('Unable to close index [%s] and update normalizer settings.', $name),
                ['exception' => $e, 'index_name' => $name]
            );

            return;
        }

        $this->logger->info(sprintf('Successfully added missing normalizers to index [%s]', $name));
    }
360467
protected function dispatchEventWithModel($name, Model $model)
    {
        $this->pool->eventService->dispatch(
            static::$eventPrefix . '::' . $name,
            $this,
            $model
        );

        return $model;
    }
625357
private function router($name, $val)
    {
        // Route object
        if (is_object($val)) {
            $this->renderObj($name, $val);
        }

        // Route indexed array
        if (is_array($val) && Utils::isArrayIndexed($val)) {
            $this->renderArrIndexed($name, $val);
        }

        // Route array with keys
        if (is_array($val) && !Utils::isArrayIndexed($val)) {
            $this->renderArrKeys($name, $val);
        }

        // Route strings/other
        if (!is_array($val) && !is_object($val)) {
            // Add to $this->code
            $this->renderResult($name, $val);

            // Clear out $this-code
            $this->code = '';

            // Exit
            return;
        }
    }
1344776
protected function renderBlock($name, $parameters)
    {
        /** @var Twig_TemplateInterface $template */
        foreach ($this->getTemplates() as $template) {
            if ($template->hasBlock($name)) {

                $context = array_merge(
                    $template->getEnvironment()->getGlobals(),
                    $parameters
                );

                return $template->renderBlock($name, $context);
            }
        }

        throw new \InvalidArgumentException(sprintf('Block "%s" doesn\'t exist in grid template.', $name));
    }
793022
public static function getList(string $name, int $index): string
    {
        $obj = new RedisList(self::handle(), $name);
        return $obj->get($index);
    }