/** * {@inheritdoc} */ public function getUrl() { $url = parent::getUrl(); if (!$this->resolved && $url !== null) { $this->setUrl(Macro::resolveMacros($url->getAbsoluteUrl(), $this->getObject())); $this->resolved = true; } return $url; }
/** * {@inheritdoc} */ public function render() { $url = Url::fromRequest(); $activeLimit = (int) $url->getParam('limit', $this->getDefaultLimit()); $navigation = new Navigation(); $navigation->setLayout(Navigation::LAYOUT_TABS); foreach (static::$limits as $limit => $label) { $navigationItem = new NavigationItem($limit); $navigationItem->setActive($activeLimit === $limit)->setAttribute('title', sprintf(t('Show %u rows on this page'), $limit))->setLabel($label)->setUrl($url->with(array('limit' => $limit))); $navigation->addItem($navigationItem); } if ($activeLimit === 0) { $navigationItem = new NavigationItem(0); $navigationItem->setActive(true)->setAttribute('title', t('Show all items on this page'))->setLabel(t('all')); $navigation->addItem($navigationItem); } return $navigation->getRenderer()->setCssClass(static::CSS_CLASS_LIMITER)->setHeading(t('Limiter'))->render(); }
/** * Return whether it's possible to merge this item with the given one * * @param NavigationItem $item * * @return bool */ public function conflictsWith(NavigationItem $item) { if (!$item instanceof $this) { return true; } if ($this->getUrl() === null || $item->getUrl() === null) { return false; } return !$this->getUrl()->matches($item->getUrl()); }
/** * Return whether the first item is less than, more than or equal to the second one * * @param NavigationItem $a * @param NavigationItem $b * * @return int */ protected function compareItems(NavigationItem $a, NavigationItem $b) { if ($a->getPriority() === $b->getPriority()) { return strcasecmp($a->getLabel(), $b->getLabel()); } return $a->getPriority() > $b->getPriority() ? 1 : -1; }
/** * {@inheritdoc} */ public function merge(NavigationItem $item) { parent::merge($item); $this->setDashlets(array_merge($this->getDashlets(false), $item->getDashlets(false))); }
/** * Return the opening markup for the given navigation item * * @param NavigationItem $item * * @return string */ public function beginItemMarkup(NavigationItem $item) { $cssClass = array(static::CSS_CLASS_ITEM); if ($item->hasChildren() && $item->getChildren()->getLayout() === Navigation::LAYOUT_DROPDOWN) { $cssClass[] = static::CSS_CLASS_DROPDOWN; $item->setAttribute('class', static::CSS_CLASS_DROPDOWN_TOGGLE)->setIcon(static::DROPDOWN_TOGGLE_ICON)->setUrl('#'); } if ($item->getActive()) { $cssClass[] = static::CSS_CLASS_ACTIVE; } $content = sprintf('<li id="%s" class="%s">', $this->view()->escape($item->getUniqueName()), join(' ', $cssClass)); return $content; }
/** * Return the opening markup for the given navigation item * * @param NavigationItem $item * * @return string */ public function beginItemMarkup(NavigationItem $item) { $cssClasses = array(static::CSS_CLASS_ITEM); if ($item->hasChildren() && $item->getChildren()->getLayout() === Navigation::LAYOUT_DROPDOWN) { $cssClasses[] = static::CSS_CLASS_DROPDOWN; $item->setAttribute('class', static::CSS_CLASS_DROPDOWN_TOGGLE)->setIcon(static::DROPDOWN_TOGGLE_ICON)->setUrl('#'); } if ($item->getActive()) { $cssClasses[] = static::CSS_CLASS_ACTIVE; } if ($item->getIcon() === null) { // @TODO(el): Add constant $cssClasses[] = 'no-icon'; } if ($cssClass = $item->getCssClass()) { $cssClasses[] = $cssClass; } $content = sprintf('<li class="%s">', join(' ', $cssClasses)); return $content; }
/** * Create a badge group * * @param array $states * @param Navigation $badges * * @return $this */ public function createBadgeGroup(array $states, Navigation $badges) { $group = array_intersect_key($this->badges, array_flip($states)); if (!empty($group)) { $groupItem = new NavigationItem(uniqid(), array('label' => '', 'priority' => $this->priority++)); $groupBadges = new Navigation(); $groupBadges->setLayout(Navigation::LAYOUT_TABS); foreach (array_keys($group) as $state) { $this->createBadge($state, $groupBadges); } $groupItem->setChildren($groupBadges); $badges->addItem($groupItem); } return $this; }