/** * Gets a list of all URLs present in current crumbs stack. * * @return array List of URLs */ protected function _crumbs() { static $crumbs = null; if ($crumbs === null) { $crumbs = BreadcrumbRegistry::getUrls(); foreach ($crumbs as &$crumb) { $crumb = $this->sanitize($crumb); } } return $crumbs; }
/** * Adds a new crumb to the stack. * * You can use this method without any argument, if you do, it will * automatically try to guess the full breadcrumb path based on current URL (if * current URL matches any URL in any of your menu links). * * ```php * $this->Breadcrumb->push(); * ``` * * Also, you can can pass a string as first argument representing an URL, if you * do, it will try to find that URL in in any of your menus, and then generate * its corresponding breadcrumb. * * ```php * $this->Breadcrumb->push('/admin/some/url'); * ``` * * @param array|string|null $crumbs Single crumb or an array of multiple crumbs * to push at once. Or null for guess from current URL * @param mixed $url If both $crumbs and $url are string values they will be * used as `title` and `URL` respectively * @return $this For method chaining * @see \Menu\View\BreadcrumbRegistry::push() */ public function push($crumbs = null, $url = null) { if ($crumbs === null && $url === null) { $MenuLinks = TableRegistry::get('Menu.MenuLinks'); $MenuLinks->removeBehavior('Tree'); $possibleMatches = $this->_urlChunk(); $found = $MenuLinks->find()->select(['id', 'menu_id'])->where(['MenuLinks.url IN' => empty($possibleMatches) ? ['-1'] : $possibleMatches])->first(); $crumbs = []; if ($found) { $MenuLinks->addBehavior('Tree', ['scope' => ['menu_id' => $found->menu_id]]); $crumbs = $MenuLinks->find('path', ['for' => $found->id])->toArray(); } } elseif (is_string($crumbs) && strpos($crumbs, '/') !== false && $url === null) { $MenuLinks = TableRegistry::get('Menu.MenuLinks'); $MenuLinks->removeBehavior('Tree'); $found = $MenuLinks->find()->select(['id', 'menu_id'])->where(['MenuLinks.url IN' => empty($crumbs) ? ['-1'] : $crumbs])->first(); $crumbs = []; if ($found) { $MenuLinks->addBehavior('Tree', ['scope' => ['menu_id' => $found->menu_id]]); $crumbs = $MenuLinks->find('path', ['for' => $found->id])->toArray(); } } if (is_array($crumbs) || is_string($crumbs)) { BreadcrumbRegistry::push($crumbs, $url); } return $this; }