kartik\tree\TreeView::initOptions PHP Méthode

initOptions() public méthode

Initialize all options & settings for the widget
public initOptions ( )
    public function initOptions()
    {
        if (!$this->_module->treeStructure['treeAttribute']) {
            $this->allowNewRoots = false;
        }
        $this->_nodes = $this->query->all();
        $this->_iconPrefix = $this->fontAwesome ? 'fa fa-' : 'glyphicon glyphicon-';
        $this->_nodeSelected = $this->options['id'] . '-nodesel';
        if (empty($this->buttonIconOptions['class'])) {
            $this->buttonIconOptions['class'] = $this->fontAwesome ? 'kv-icon-10' : 'kv-icon-05';
        }
        $this->options['data-key'] = $this->displayValue;
        if (empty($this->options['class'])) {
            $this->options['class'] = 'form-control hide';
        }
        Html::addCssClass($this->headerOptions, 'kv-header-container');
        Html::addCssClass($this->headingOptions, 'kv-heading-container');
        Html::addCssClass($this->toolbarOptions, 'kv-toolbar-container');
        Html::addCssClass($this->footerOptions, 'kv-footer-container');
        $css = 'kv-tree-container';
        if ($this->showCheckbox) {
            $css .= ' kv-has-checkbox';
        }
        if (!$this->multiple) {
            $css .= ' kv-single-select';
        }
        Html::addCssClass($this->treeOptions, $css);
        Html::addCssClass($this->rootOptions, 'kv-tree-root');
        Html::addCssClass($this->nodeToggleOptions, 'kv-node-toggle');
        Html::addCssClass($this->nodeCheckboxOptions, 'kv-node-checkbox');
        Html::addCssClass($this->rootNodeToggleOptions, 'kv-root-node-toggle');
        Html::addCssClass($this->rootNodeCheckboxOptions, 'kv-root-node-checkbox');
        Html::addCssClass($this->detailOptions, 'kv-detail-container');
        Html::addCssClass($this->searchContainerOptions, 'kv-search-container');
        Html::addCssClass($this->searchOptions, 'kv-search-input');
        Html::addCssClass($this->searchClearOptions, 'kv-search-clear');
        Html::addCssClass($this->expandNodeOptions, 'kv-node-expand');
        Html::addCssClass($this->collapseNodeOptions, 'kv-node-collapse');
        Html::addCssClass($this->childNodeIconOptions, 'kv-node-icon');
        Html::addCssClass($this->parentNodeIconOptions, 'kv-node-icon');
        Html::addCssClass($this->childNodeIconOptions, 'kv-icon-child');
        Html::addCssClass($this->parentNodeIconOptions, 'kv-icon-parent');
        if (empty($this->searchClearOptions['title'])) {
            $this->searchClearOptions['title'] = Yii::t('kvtree', 'Clear search results');
        }
        Html::addCssClass($this->buttonGroupOptions, 'btn-group');
        $this->treeWrapperOptions['id'] = $this->options['id'] . '-wrapper';
        $this->treeOptions['id'] = $this->options['id'] . '-tree';
        $this->detailOptions['id'] = $this->options['id'] . '-detail';
        $this->toolbarOptions['id'] = $this->options['id'] . '-toolbar';
        if (!isset($this->searchOptions['placeholder'])) {
            $this->searchOptions['placeholder'] = Yii::t('kvtree', 'Search...');
        }
        $this->toolbarOptions['role'] = 'toolbar';
        $this->buttonGroupOptions['role'] = 'group';
        $this->clientMessages += ['invalidCreateNode' => Yii::t('kvtree', 'Cannot create node. Parent node is not saved or is invalid.'), 'emptyNode' => Yii::t('kvtree', '(new)'), 'removeNode' => Yii::t('kvtree', 'Are you sure you want to remove this node?'), 'nodeRemoved' => Yii::t('kvtree', 'The node was removed successfully.'), 'nodeRemoveError' => Yii::t('kvtree', 'Error while removing the node. Please try again later.'), 'nodeNewMove' => Yii::t('kvtree', 'Cannot move this node as the node details are not saved yet.'), 'nodeTop' => Yii::t('kvtree', 'Already at top-most node in the hierarchy.'), 'nodeBottom' => Yii::t('kvtree', 'Already at bottom-most node in the hierarchy.'), 'nodeLeft' => Yii::t('kvtree', 'Already at left-most node in the hierarchy.'), 'nodeRight' => Yii::t('kvtree', 'Already at right-most node in the hierarchy.'), 'emptyNodeRemoved' => Yii::t('kvtree', 'The untitled node was removed.'), 'selectNode' => Yii::t('kvtree', 'Select a node by clicking on one of the tree items.')];
        $defaultToolbar = [self::BTN_CREATE => ['icon' => 'plus', 'options' => ['title' => Yii::t('kvtree', 'Add new'), 'disabled' => true]], self::BTN_CREATE_ROOT => ['icon' => $this->fontAwesome ? 'tree' : 'tree-conifer', 'options' => ['title' => Yii::t('kvtree', 'Add new root')]], self::BTN_REMOVE => ['icon' => 'trash', 'options' => ['title' => Yii::t('kvtree', 'Delete'), 'disabled' => true]], self::BTN_SEPARATOR, self::BTN_MOVE_UP => ['icon' => 'arrow-up', 'options' => ['title' => Yii::t('kvtree', 'Move Up'), 'disabled' => true]], self::BTN_MOVE_DOWN => ['icon' => 'arrow-down', 'options' => ['title' => Yii::t('kvtree', 'Move Down'), 'disabled' => true]], self::BTN_MOVE_LEFT => ['icon' => 'arrow-left', 'options' => ['title' => Yii::t('kvtree', 'Move Left'), 'disabled' => true]], self::BTN_MOVE_RIGHT => ['icon' => 'arrow-right', 'options' => ['title' => Yii::t('kvtree', 'Move Right'), 'disabled' => true]], self::BTN_SEPARATOR, self::BTN_REFRESH => ['icon' => 'refresh', 'options' => ['title' => Yii::t('kvtree', 'Refresh')], 'url' => Yii::$app->request->url]];
        if (!$this->allowNewRoots) {
            unset($defaultToolbar[self::BTN_CREATE_ROOT]);
        }
        $this->toolbar = array_replace_recursive($defaultToolbar, $this->toolbar);
        $this->sortToolbar();
        if ($this->defaultChildNodeIcon === null) {
            $this->defaultChildNodeIcon = $this->getNodeIcon(1);
        }
        if ($this->defaultParentNodeIcon === null) {
            $this->defaultParentNodeIcon = $this->getNodeIcon(2);
        }
        if ($this->defaultParentNodeOpenIcon === null) {
            $this->defaultParentNodeOpenIcon = $this->getNodeIcon(3);
        }
        $this->_iconsList = $this->getIconsList();
    }