Source of file CrumbNavigation.php
Size: 6,405 Bytes - Last Modified: 2021-12-23T10:36:59+00:00
/var/www/docs.ssmods.com/process/src/src/Components/CrumbNavigation.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 | <?php /** * This file is part of SilverWare. * * PHP version >=5.6.0 * * For full copyright and license information, please view the * LICENSE.md file that was distributed with this source code. * * @package SilverWare\Navigation\Components * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-navigation */ namespace SilverWare\Navigation\Components; use SilverStripe\Forms\CheckboxField; use SilverWare\Components\BaseComponent; use SilverWare\Forms\FieldSection; use Page; use PageController; /** * An extension of the base component class for crumb navigation. * * @package SilverWare\Navigation\Components * @author Colin Tucker <colin@praxis.net.au> * @copyright 2017 Praxis Interactive * @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause * @link https://github.com/praxisnetau/silverware-navigation */ class CrumbNavigation extends BaseComponent { /** * Human-readable singular name. * * @var string * @config */ private static $singular_name = 'Crumb Navigation'; /** * Human-readable plural name. * * @var string * @config */ private static $plural_name = 'Crumb Navigation'; /** * Description of this object. * * @var string * @config */ private static $description = 'A component which shows crumb navigation for the current page'; /** * Icon file for this object. * * @var string * @config */ private static $icon = 'silverware/navigation: admin/client/dist/images/icons/CrumbNavigation.png'; /** * Defines the table name to use for this object. * * @var string * @config */ private static $table_name = 'SilverWare_CrumbNavigation'; /** * Defines an ancestor class to hide from the admin interface. * * @var string * @config */ private static $hide_ancestor = BaseComponent::class; /** * Defines the allowed children for this object. * * @var array|string * @config */ private static $allowed_children = 'none'; /** * Maps field names to field types for this object. * * @var array * @config */ private static $db = [ 'HideTopLevel' => 'Boolean' ]; /** * Defines the default values for the fields of this object. * * @var array * @config */ private static $defaults = [ 'HideTitle' => 1, 'HideTopLevel' => 1 ]; /** * Answers a list of field objects for the CMS interface. * * @return FieldList */ public function getCMSFields() { // Obtain Field Objects (from parent): $fields = parent::getCMSFields(); // Create Options Fields: $fields->addFieldToTab( 'Root.Options', FieldSection::create( 'NavigationOptions', $this->fieldLabel('NavigationOptions'), [ CheckboxField::create( 'HideTopLevel', $this->fieldLabel('HideTopLevel') ) ] ) ); // Answer Field Objects: return $fields; } /** * Answers the labels for the fields of the receiver. * * @param boolean $includerelations Include labels for relations. * * @return array */ public function fieldLabels($includerelations = true) { // Obtain Field Labels (from parent): $labels = parent::fieldLabels($includerelations); // Define Field Labels: $labels['HideTopLevel'] = _t(__CLASS__ . '.HIDETOPLEVEL', 'Hide crumbs on top-level pages'); $labels['NavigationOptions'] = _t(__CLASS__ . '.NAVIGATION', 'Navigation'); // Answer Field Labels: return $labels; } /** * Answers the breadcrumb items from the current controller. * * @return ArrayList */ public function getCrumbs() { if ($controller = $this->getCurrentController(PageController::class)) { return $controller->getBreadcrumbItems(); } } /** * Answers the number of breadcrumb items from the current controller. * * @return integer */ public function getCrumbsCount() { return ($crumbs = $this->getCrumbs()) ? $crumbs->count() : 0; } /** * Answers an array of wrapper class names for the HTML template. * * @return array */ public function getWrapperClassNames() { $classes = $this->styles('breadcrumb'); $this->extend('updateWrapperClassNames', $classes); return $classes; } /** * Answers an array of item class names for the HTML template. * * @return array */ public function getItemClassNames() { $classes = $this->styles('breadcrumb.item'); $this->extend('updateItemClassNames', $classes); return $classes; } /** * Answers an array of active class names for the HTML template. * * @return array */ public function getActiveClassNames() { $classes = $this->styles('breadcrumb.item', 'breadcrumb.active'); $this->extend('updateActiveClassNames', $classes); return $classes; } /** * Answers true if the object is disabled within the template. * * @return boolean */ public function isDisabled() { // Obtain Current Page (with crumbs enabled): if (($page = $this->getCurrentPage(Page::class)) && !$page->CrumbsDisabled) { // Disable for Top-Level (if required): if ($this->HideTopLevel && $this->getCrumbsCount() == 1) { return true; } // Answer from Parent: return parent::isDisabled(); } // Disable (by default): return true; } } |