Source for file list.php
Documentation is available at list.php
* @package FrameworkOnFramework
* @copyright Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
// Protect from unauthorized access
require_once JPATH_LIBRARIES .
'/joomla/form/fields/list.php';
* Form Field class for FOF
* Supports a generic list of options.
* @package FrameworkOnFramework
/** @var FOFTable The item being rendered in a repeatable form field */
/** @var int A monotonically increasing number, denoting the row number in a repeatable view */
* Method to get certain otherwise inaccessible properties from the form field object.
* @param string $name The property name for which to the the value.
* @return mixed The property value or null.
public function __get($name)
return parent::__get($name);
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
* @return string The field HTML
$class =
$this->element['class'] ?
' class="' . (string)
$this->element['class'] .
'"' :
'';
return '<span id="' .
$this->id .
'" ' .
$class .
'>' .
* Get the rendering of this field type for a repeatable (grid) display,
* e.g. in a view listing many item (typically a "browse" task)
* @return string The field HTML
$class =
$this->element['class'] ? (string)
$this->element['class'] :
'';
if ($this->element['show_link'] ==
'true')
// Replace [ITEM:ID] in the URL with the item's key value (usually:
// the auto-incrementing numeric ID)
$replace =
$this->item->$keyfield;
$link_url =
str_replace('[ITEM:ID]', $replace, $link_url);
// Replace other field variables in the URL
foreach ($fields as $fielddata)
$fieldname =
$fielddata->Field;
$fieldname =
$fielddata->column_name;
$search =
'[ITEM:' .
strtoupper($fieldname) .
']';
$replace =
$this->item->$fieldname;
$html =
'<span class="' .
$this->id .
' ' .
$class .
'">';
$html .=
'<a href="' .
$link_url .
'">';
* Gets the active option's label given an array of JHtml options
* @param array $data The JHtml options to parse
* @param mixed $selected The currently selected value
* @param string $optKey Key name
* @param string $optText Value name
* @return mixed The label of the currently selected option
public static function getOptionName($data, $selected =
null, $optKey =
'value', $optText =
'text')
foreach ($data as $elementKey =>
&$element)
$key =
$optKey ===
null ?
$elementKey :
$element[$optKey];
$text =
$element[$optText];
$key =
$optKey ===
null ?
$elementKey :
$element->$optKey;
$text =
$element->$optText;
// This is a simple associative array
elseif ($selected ==
$key)
* Method to get the field options.
* Ordering is disabled by default. You can enable ordering by setting the
* 'order' element in your form field. The other order values are optional.
* - order What to order. Possible values: 'name' or 'value' (default = false)
* - order_dir Order direction. Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc')
* - order_case_sensitive Order case sensitive. Possible values: 'true' or 'false' (default = false)
* @return array The field option objects.
* @since Ordering is available since FOF 2.1.b2.
// Ordering is disabled by default for backward compatibility
// Set default order direction
// Set default value for case sensitive sorting
$order_case_sensitive =
false;
$order_dir =
$this->element['order_dir'];
if ($this->element['order_case_sensitive'])
// Override default setting when the form element value is 'true'
if ($this->element['order_case_sensitive'] ==
'true')
$order_case_sensitive =
true;
// Create a $sortOptions array in order to apply sorting
foreach ($this->element->children() as $option)
$sortOptions[$i] =
new stdClass;
$sortOptions[$i]->option =
$option;
$sortOptions[$i]->value =
$option['value'];
$sortOptions[$i]->name =
$name;
// Only order if it's set
jimport('joomla.utilities.arrayhelper');
// Initialise the options
// Do we have a class and method source for our options?
$source_file =
empty($this->element['source_file']) ?
'' : (string)
$this->element['source_file'];
$source_class =
empty($this->element['source_class']) ?
'' : (string)
$this->element['source_class'];
$source_method =
empty($this->element['source_method']) ?
'' : (string)
$this->element['source_method'];
$source_key =
empty($this->element['source_key']) ?
'*' : (string)
$this->element['source_key'];
$source_value =
empty($this->element['source_value']) ?
'*' : (string)
$this->element['source_value'];
$source_translate =
empty($this->element['source_translate']) ?
'true' : (string)
$this->element['source_translate'];
$source_translate =
in_array(strtolower($source_translate), array('true','yes','1','on')) ?
true :
false;
if ($source_class &&
$source_method)
// Maybe we have to load a file?
if (!empty($source_file))
include_once $source_file;
// Make sure the class exists
// ...and so does the option
// Get the data from the class
$source_data =
$source_class::$source_method();
// Loop through the data and prime the $options array
foreach ($source_data as $k =>
$v)
$key =
(empty($source_key) ||
($source_key ==
'*')) ?
$k :
$v[$source_key];
$value =
(empty($source_value) ||
($source_value ==
'*')) ?
$v :
$v[$source_value];
$value =
JText::_($value);
$options[] =
JHtml::_('select.option', $key, $value, 'value', 'text');
// Get the field $options
foreach ($sortOptions as $sortOption)
$option =
$sortOption->option;
$name =
$sortOption->name;
// Only add <option /> elements.
if ($option->getName() !=
'option')
$tmp =
JHtml::_('select.option', (string)
$option['value'], $name, 'value', 'text', ((string)
$option['disabled'] ==
'true'));
// Set some option attributes.
$tmp->class = (string)
$option['class'];
// Set some JavaScript option attributes.
$tmp->onclick = (string)
$option['onclick'];
// Add the option object to the result set.
Documentation generated on Tue, 19 Nov 2013 15:07:13 +0100 by phpDocumentor 1.4.3