record = $record; } /** * @return SS_List of SilverStripeNavigatorItem */ public function getItems() { $items = []; $classes = ClassInfo::subclassesFor(SilverStripeNavigatorItem::class); array_shift($classes); // Sort menu items according to priority foreach ($classes as $class) { /** @var SilverStripeNavigatorItem $item */ $item = new $class($this->record); if (!$item->canView()) { continue; } // This funny litle formula ensures that the first item added with the same priority will be left-most. $priority = $item->getPriority() * 100 - 1; // Ensure that we can have duplicates with the same (default) priority while (isset($items[$priority])) { $priority++; } $items[$priority] = $item; } ksort($items); // Drop the keys and let the ArrayList handle the numbering, so $IsFirst, $IsLast and others work properly. return new ArrayList(array_values($items ?? [])); } /** * @return DataObject|\SilverStripe\ORM\CMSPreviewable */ public function getRecord() { return $this->record; } /** * @param DataObject|CMSPreviewable $record * @return array template data */ public static function get_for_record($record) { $html = ''; $message = ''; $navigator = new SilverStripeNavigator($record); $items = $navigator->getItems(); foreach ($items as $item) { $text = $item->getHTML(); if ($text) { $html .= $text; } $newMessage = $item->getMessage(); if ($newMessage && $item->isActive()) { $message = $newMessage; } } return [ 'items' => $html, 'message' => $message ]; } }