Source for file menuitem.php

Documentation is available at menuitem.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Form
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. JFormHelper::loadFieldClass('groupedlist');
  13.  
  14. // Import the com_menus helper.
  15. require_once realpath(JPATH_ADMINISTRATOR '/components/com_menus/helpers/menus.php');
  16.  
  17. /**
  18.  * Supports an HTML grouped select list of menu item grouped by menu
  19.  *
  20.  * @package     Joomla.Libraries
  21.  * @subpackage  Form
  22.  * @since       1.6
  23.  */
  24. {
  25.     /**
  26.      * The form field type.
  27.      *
  28.      * @var    string 
  29.      * @since  1.6
  30.      */
  31.     public $type = 'MenuItem';
  32.  
  33.     /**
  34.      * The menu type.
  35.      *
  36.      * @var    string 
  37.      * @since  3.2
  38.      */
  39.     protected $menuType;
  40.  
  41.     /**
  42.      * The language.
  43.      *
  44.      * @var    array 
  45.      * @since  3.2
  46.      */
  47.     protected $language;
  48.  
  49.     /**
  50.      * The published status.
  51.      *
  52.      * @var    array 
  53.      * @since  3.2
  54.      */
  55.     protected $published;
  56.  
  57.     /**
  58.      * The disabled status.
  59.      *
  60.      * @var    array 
  61.      * @since  3.2
  62.      */
  63.     protected $disable;
  64.  
  65.     /**
  66.      * Method to get certain otherwise inaccessible properties from the form field object.
  67.      *
  68.      * @param   string  $name  The property name for which to the the value.
  69.      *
  70.      * @return  mixed  The property value or null.
  71.      *
  72.      * @since   3.2
  73.      */
  74.     public function __get($name)
  75.     {
  76.         switch ($name)
  77.         {
  78.             case 'menuType':
  79.             case 'language':
  80.             case 'published':
  81.             case 'disable':
  82.                 return $this->$name;
  83.         }
  84.  
  85.         return parent::__get($name);
  86.     }
  87.  
  88.     /**
  89.      * Method to set certain otherwise inaccessible properties of the form field object.
  90.      *
  91.      * @param   string  $name   The property name for which to the the value.
  92.      * @param   mixed   $value  The value of the property.
  93.      *
  94.      * @return  void 
  95.      *
  96.      * @since   3.2
  97.      */
  98.     public function __set($name$value)
  99.     {
  100.         switch ($name)
  101.         {
  102.             case 'menuType':
  103.                 $this->menuType = (string) $value;
  104.                 break;
  105.  
  106.             case 'language':
  107.             case 'published':
  108.             case 'disable':
  109.                 $value = (string) $value;
  110.                 $this->$name $value explode(','$valuearray();
  111.                 break;
  112.  
  113.             default:
  114.                 parent::__set($name$value);
  115.         }
  116.     }
  117.  
  118.     /**
  119.      * Method to attach a JForm object to the field.
  120.      *
  121.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  122.      * @param   mixed             $value    The form field value to validate.
  123.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  124.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  125.      *                                       full field name would end up being "bar[foo]".
  126.      *
  127.      * @return  boolean  True on success.
  128.      *
  129.      * @see     JFormField::setup()
  130.      * @since   3.2
  131.      */
  132.     public function setup(SimpleXMLElement $element$value$group null)
  133.     {
  134.         $result parent::setup($element$value$group);
  135.  
  136.         if ($result == true)
  137.         {
  138.             $this->menuType  = (string) $this->element['menu_type'];
  139.             $this->published = $this->element['published'explode(','(string) $this->element['published']array();
  140.             $this->disable   = $this->element['disable'explode(','(string) $this->element['disable']array();
  141.             $this->language  = $this->element['language'explode(','(string) $this->element['language']array();
  142.         }
  143.  
  144.         return $result;
  145.     }
  146.  
  147.     /**
  148.      * Method to get the field option groups.
  149.      *
  150.      * @return  array  The field option objects as a nested array in groups.
  151.      *
  152.      * @since   1.6
  153.      */
  154.     protected function getGroups()
  155.     {
  156.         $groups array();
  157.  
  158.         $menuType $this->menuType;
  159.  
  160.         // Get the menu items.
  161.         $items MenusHelper::getMenuLinks($menuType00$this->published$this->language);
  162.  
  163.         // Build group for a specific menu type.
  164.         if ($menuType)
  165.         {
  166.             // Initialize the group.
  167.             $groups[$menuTypearray();
  168.  
  169.             // Build the options array.
  170.             foreach ($items as $link)
  171.             {
  172.                 $groups[$menuType][JHtml::_('select.option'$link->value$link->text'value''text'in_array($link->type$this->disable));
  173.             }
  174.         }
  175.         // Build groups for all menu types.
  176.         else
  177.         {
  178.             // Build the groups arrays.
  179.             foreach ($items as $menu)
  180.             {
  181.                 // Initialize the group.
  182.                 $groups[$menu->menutypearray();
  183.  
  184.                 // Build the options array.
  185.                 foreach ($menu->links as $link)
  186.                 {
  187.                     $groups[$menu->menutype][JHtml::_(
  188.                         'select.option'$link->value$link->text'value''text',
  189.                         in_array($link->type$this->disable)
  190.                     );
  191.                 }
  192.             }
  193.         }
  194.  
  195.         // Merge any additional groups in the XML definition.
  196.         $groups array_merge(parent::getGroups()$groups);
  197.  
  198.         return $groups;
  199.     }
  200. }

Documentation generated on Tue, 19 Nov 2013 15:07:56 +0100 by phpDocumentor 1.4.3