/** * Generate and return the breadcrumbs for the node * * @param int $depth the breadcrumbs parent depth * @param string $glue the pattern to separate the breadcrumbs * @param string $currNodeCss the CSS class to be set for current node * @param string $untitled the name to be displayed for a new node * * @return string the parsed breadcrumbs */ public function getBreadcrumbs($depth = 1, $glue = ' » ', $currNodeCss = 'kv-crumb-active', $untitled = 'Untitled') { /** * @var Tree $this */ if ($this->isNewRecord || empty($this)) { return $currNodeCss ? Html::tag('span', $untitled, ['class' => $currNodeCss]) : $untitled; } $depth = empty($depth) ? null : intval($depth); $module = TreeView::module(); $nameAttribute = ArrayHelper::getValue($module->dataStructure, 'nameAttribute', 'name'); $crumbNodes = $depth === null ? $this->parents()->all() : $this->parents($depth - 1)->all(); $crumbNodes[] = $this; $i = 1; $len = count($crumbNodes); $crumbs = []; foreach ($crumbNodes as $node) { $name = $node->{$nameAttribute}; if ($i === $len && $currNodeCss) { $name = Html::tag('span', $name, ['class' => $currNodeCss]); } $crumbs[] = $name; $i++; } return implode($glue, $crumbs); }
/** * Renders the markup for the button actions toolbar * * @return string */ public function renderToolbar() { if (!$this->showToolbar) { return ''; } unset($this->toolbar[self::BTN_CREATE], $this->toolbar[self::BTN_CREATE_ROOT], $this->toolbar[self::BTN_REMOVE]); return parent::renderToolbar(); }
* SECTION 1: Initialize node view params & setup helper methods. */ extract($params); $isAdmin = $isAdmin == true || $isAdmin === "true"; // admin mode flag $inputOpts = []; // readonly/disabled input options for node $flagOptions = ['class' => 'kv-parent-flag']; // node options for parent/child // parse parent key if (empty($parentKey)) { $parent = $node->parents(1)->one(); $parentKey = empty($parent) ? '' : Html::getAttributeValue($parent, $keyAttribute); } // get module and setup form $module = TreeView::module(); // the treemanager module $formOptions['id'] = 'kv-' . uniqid(); $form = ActiveForm::begin(['action' => $action, 'options' => $formOptions]); // the primary key input field if ($showIDAttribute) { $options = ['readonly' => true]; if ($node->isNewRecord) { $options['value'] = Yii::t('kvtree', '(new)'); } $keyField = $form->field($node, $keyAttribute)->textInput($options); } else { $keyField = Html::activeHiddenInput($node, $keyAttribute); } // initialize for create or update $depth = ArrayHelper::getValue($breadcrumbs, 'depth');
/** * View, create, or update a tree node via ajax * * @return string json encoded response */ public function actionManage() { Yii::$app->response->format = Response::FORMAT_JSON; static::checkValidRequest(); $parentKey = $action = null; $modelClass = '\\oreolek\\tree\\models\\Tree'; $isAdmin = $softDelete = $showFormButtons = $showIDAttribute = false; $currUrl = $nodeView = $formOptions = $formAction = $breadCrumbs = $nodeSelected = ''; $iconsList = $nodeAddlViews = []; extract(static::getPostData()); /** * @var Tree $modelClass * @var Tree $node */ if (!isset($id) || empty($id)) { $node = new $modelClass(); $node->initDefaults(); } else { $node = $modelClass::findOne($id); } $module = TreeView::module(); $params = $module->treeStructure + $module->dataStructure + ['node' => $node, 'parentKey' => $parentKey, 'action' => $formAction, 'formOptions' => empty($formOptions) ? [] : $formOptions, 'modelClass' => $modelClass, 'currUrl' => $currUrl, 'isAdmin' => $isAdmin, 'iconsList' => $iconsList, 'softDelete' => $softDelete, 'showFormButtons' => $showFormButtons, 'showIDAttribute' => $showIDAttribute, 'nodeView' => $nodeView, 'nodeAddlViews' => $nodeAddlViews, 'nodeSelected' => $nodeSelected, 'breadcrumbs' => empty($breadcrumbs) ? [] : $breadcrumbs]; if (!empty($module->unsetAjaxBundles)) { Event::on(View::className(), View::EVENT_AFTER_RENDER, function ($e) use($module) { foreach ($module->unsetAjaxBundles as $bundle) { unset($e->sender->assetBundles[$bundle]); } }); } $callback = function () use($nodeView, $params) { return $this->renderAjax($nodeView, ['params' => $params]); }; return self::process($callback, Yii::t('kvtree', 'Error while viewing the node. Please try again later.'), null); }