Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
predefinedlist.php
Aller à la documentation de ce fichier.
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('list');
13 
14 /**
15  * Form Field to load a list of predefined values
16  *
17  * @package Joomla.Libraries
18  * @subpackage Form
19  * @since 3.2
20  */
22 {
23  /**
24  * The form field type.
25  *
26  * @var string
27  * @since 3.2
28  */
29  protected $type = 'PredefinedList';
30 
31  /**
32  * Cached array of the category items.
33  *
34  * @var array
35  * @since 3.2
36  */
37  protected static $options = array();
38 
39  /**
40  * Available predefined options
41  *
42  * @var array
43  * @since 3.2
44  */
45  protected $predefinedOptions = array();
46 
47  /**
48  * Translate options labels ?
49  *
50  * @var boolean
51  * @since 3.2
52  */
53  protected $translate = true;
54 
55  /**
56  * Method to get the options to populate list
57  *
58  * @return array The field option objects.
59  *
60  * @since 3.2
61  */
62  protected function getOptions()
63  {
64  // Hash for caching
65  $hash = md5($this->element);
66  $type = strtolower($this->type);
67 
68  if (!isset(static::$options[$type][$hash]) && !empty($this->predefinedOptions))
69  {
70  static::$options[$type][$hash] = parent::getOptions();
71 
72  $options = array();
73 
74  // Allow to only use specific values of the predefined list
75  $filter = isset($this->element['filter']) ? explode(',', $this->element['filter']) : array();
76 
77  foreach ($this->predefinedOptions as $value => $text)
78  {
79  if (empty($filter) || in_array($value, $filter))
80  {
81  $text = $this->translate ? JText::_($text) : $text;
82 
83  $options[] = (object) array(
84  'value' => $value,
85  'text' => $text
86  );
87  }
88  }
89 
90  static::$options[$type][$hash] = array_merge(static::$options[$type][$hash], $options);
91  }
92 
93  return static::$options[$type][$hash];
94  }
95 }