[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/HTML/Helpers/ -> Sidebar.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\HTML\Helpers;
  11  
  12  use Joomla\CMS\Factory;
  13  use Joomla\CMS\Layout\FileLayout;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Utility class to render a list view sidebar
  21   *
  22   * @since  3.0
  23   */
  24  abstract class Sidebar
  25  {
  26      /**
  27       * Menu entries
  28       *
  29       * @var    array
  30       * @since  3.0
  31       */
  32      protected static $entries = array();
  33  
  34      /**
  35       * Filters
  36       *
  37       * @var    array
  38       * @since  3.0
  39       */
  40      protected static $filters = array();
  41  
  42      /**
  43       * Value for the action attribute of the form.
  44       *
  45       * @var    string
  46       * @since  3.0
  47       */
  48      protected static $action = '';
  49  
  50      /**
  51       * Render the sidebar.
  52       *
  53       * @return  string  The necessary HTML to display the sidebar
  54       *
  55       * @since   3.0
  56       */
  57      public static function render()
  58      {
  59          // Collect display data
  60          $data                 = new \stdClass();
  61          $data->list           = static::getEntries();
  62          $data->filters        = static::getFilters();
  63          $data->action         = static::getAction();
  64          $data->displayMenu    = count($data->list);
  65          $data->displayFilters = count($data->filters);
  66          $data->hide           = Factory::getApplication()->input->getBool('hidemainmenu');
  67  
  68          // Create a layout object and ask it to render the sidebar
  69          $layout      = new FileLayout('joomla.sidebars.submenu');
  70  
  71          return $layout->render($data);
  72      }
  73  
  74      /**
  75       * Method to add a menu item to submenu.
  76       *
  77       * @param   string  $name    Name of the menu item.
  78       * @param   string  $link    URL of the menu item.
  79       * @param   bool    $active  True if the item is active, false otherwise.
  80       *
  81       * @return  void
  82       *
  83       * @since   3.0
  84       */
  85      public static function addEntry($name, $link = '', $active = false)
  86      {
  87          static::$entries[] = array($name, $link, $active);
  88      }
  89  
  90      /**
  91       * Returns an array of all submenu entries
  92       *
  93       * @return  array
  94       *
  95       * @since   3.0
  96       */
  97      public static function getEntries()
  98      {
  99          return static::$entries;
 100      }
 101  
 102      /**
 103       * Method to add a filter to the submenu
 104       *
 105       * @param   string  $label      Label for the menu item.
 106       * @param   string  $name       Name for the filter. Also used as id.
 107       * @param   string  $options    Options for the select field.
 108       * @param   bool    $noDefault  Don't show the label as the empty option
 109       *
 110       * @return  void
 111       *
 112       * @since   3.0
 113       */
 114      public static function addFilter($label, $name, $options, $noDefault = false)
 115      {
 116          static::$filters[] = array('label' => $label, 'name' => $name, 'options' => $options, 'noDefault' => $noDefault);
 117      }
 118  
 119      /**
 120       * Returns an array of all filters
 121       *
 122       * @return  array
 123       *
 124       * @since   3.0
 125       */
 126      public static function getFilters()
 127      {
 128          return static::$filters;
 129      }
 130  
 131      /**
 132       * Set value for the action attribute of the filter form
 133       *
 134       * @param   string  $action  Value for the action attribute of the form
 135       *
 136       * @return  void
 137       *
 138       * @since   3.0
 139       */
 140      public static function setAction($action)
 141      {
 142          static::$action = $action;
 143      }
 144  
 145      /**
 146       * Get value for the action attribute of the filter form
 147       *
 148       * @return  string
 149       *
 150       * @since   3.0
 151       */
 152      public static function getAction()
 153      {
 154          return static::$action;
 155      }
 156  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer