-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make JFormFieldCheckboxes and JFormFieldRadio subclasses of JFormFiel…
…dList so that there is only one implementation of getOptions(). New class JFormOption and assorted option-type classes to be used to generate lists of options based on the <option/> xml element. Other related changes to JForm and JFormHelper.
- Loading branch information
1 parent
fd65c24
commit 0156819
Showing
17 changed files
with
932 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* | ||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
defined('JPATH_PLATFORM') or die; | ||
|
||
/** | ||
* Abstract Form Option class for the Joomla Platform. | ||
* | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* @since 11.1 | ||
*/ | ||
abstract class JFormOption | ||
{ | ||
/** | ||
* Method to get a list of options. | ||
* | ||
* @param SimpleXMLElement $option <option/> element | ||
* @param string $fieldname The name of the field containing this option. | ||
* | ||
* @return array A list of objects representing HTML option elements (such as created by JHtmlSelect::option). | ||
* | ||
* @since 11.1 | ||
*/ | ||
public static function getOptions(SimpleXMLElement $option, $fieldname = '') | ||
{ | ||
// Filter requirements | ||
if ($requires = explode(',', (string) $option['requires'])) | ||
{ | ||
// Requires multilanguage | ||
if (in_array('multilanguage', $requires) && !JLanguageMultilang::isEnabled()) | ||
{ | ||
return array(); | ||
} | ||
|
||
// Requires associations | ||
if (in_array('associations', $requires) && !JLanguageAssociations::isEnabled()) | ||
{ | ||
return array(); | ||
} | ||
} | ||
|
||
$type = $option['type'] ? (string) $option['type'] : 'standard'; | ||
|
||
$class = JFormHelper::loadOptionClass($type); | ||
|
||
return $class ? $class::getOptions($option, $fieldname) : array(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* | ||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
defined('JPATH_PLATFORM') or die; | ||
|
||
/** | ||
* Cache Handlers Option class for the Joomla Platform. | ||
* | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* @since 11.1 | ||
*/ | ||
abstract class JFormOptionCacheHandlers | ||
{ | ||
|
||
protected $type = 'CacheHandlers'; | ||
|
||
/** | ||
* Method to get a list of options. | ||
* | ||
* @param SimpleXMLElement $option <option/> element | ||
* @param string $fieldname The name of the field containing this option. | ||
* | ||
* @return array A list of objects representing HTML option elements (such as created by JHtmlSelect::option). | ||
* | ||
* @since 11.1 | ||
*/ | ||
public static function getOptions(SimpleXMLElement $option, $fieldname = '') | ||
{ | ||
$options = array(); | ||
|
||
// Convert to name => name array. | ||
foreach (JCache::getStores() as $store) | ||
{ | ||
$options[] = JHtml::_('select.option', $store, JText::_('JLIB_FORM_VALUE_CACHE_' . $store)); | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* | ||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
defined('JPATH_PLATFORM') or die; | ||
|
||
/** | ||
* Database Connections Option class for the Joomla Platform. | ||
* | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* @since 11.1 | ||
*/ | ||
abstract class JFormOptionDatabaseConnections | ||
{ | ||
|
||
protected $type = 'DatabaseConnections'; | ||
|
||
/** | ||
* Method to get a list of options. | ||
* | ||
* @param SimpleXMLElement $option <option/> element | ||
* @param string $fieldname The name of the field containing this option. | ||
* | ||
* @return array A list of objects representing HTML option elements (such as created by JHtmlSelect::option). | ||
* | ||
* @since 11.1 | ||
*/ | ||
public static function getOptions(SimpleXMLElement $option, $fieldname = '') | ||
{ | ||
// List of options to return | ||
$options = array(); | ||
|
||
// This gets the connectors available in the platform and supported by the server. | ||
$connectors = JDatabaseDriver::getConnectors(); | ||
|
||
/** | ||
* This gets the list of database types supported by the application. | ||
* This should be entered in the form definition as a comma separated list. | ||
* If no supported databases are listed, it is assumed all available databases | ||
* are supported. | ||
*/ | ||
$supported = array_filter(array_map('trim', explode(',', $option['supported']))); | ||
if (!empty($supported)) | ||
{ | ||
$connectors = array_intersect($connectors, $supported); | ||
} | ||
|
||
foreach ($connectors as $connector) | ||
{ | ||
$options[] = JHtml::_('select.option', $connector, JText::_(ucfirst($connector))); | ||
} | ||
|
||
// This will come into play if an application is installed that requires | ||
// a database that is not available on the server. | ||
if (empty($options)) | ||
{ | ||
$options[] = JHtml::_('select.option', '', JText::_('JNONE')); | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* | ||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
defined('JPATH_PLATFORM') or die; | ||
|
||
/** | ||
* Files Option class for the Joomla Platform. | ||
* | ||
* @package Joomla.Platform | ||
* @subpackage Form | ||
* @since 11.1 | ||
*/ | ||
abstract class JFormOptionFiles | ||
{ | ||
|
||
protected $type = 'Files'; | ||
|
||
/** | ||
* Method to get a list of options. | ||
* | ||
* @param SimpleXMLElement $option <option/> element | ||
* @param string $fieldname The name of the field containing this option. | ||
* | ||
* @return array A list of objects representing HTML option elements (such as created by JHtmlSelect::option). | ||
* | ||
* @since 11.1 | ||
*/ | ||
public static function getOptions(SimpleXMLElement $option, $fieldname = '') | ||
{ | ||
$options = array(); | ||
|
||
// Initialize some field attributes. | ||
$filter = (string) $option['filter']; | ||
$exclude = (string) $option['exclude']; | ||
$stripExt = (string) $option['stripext']; | ||
$hideNone = (string) $option['hide_none']; | ||
$hideDefault = (string) $option['hide_default']; | ||
|
||
// Get the path in which to search for file options. | ||
$path = (string) $option['directory']; | ||
if (!is_dir($path)) | ||
{ | ||
$path = JPATH_ROOT . '/' . $path; | ||
} | ||
|
||
// Prepend some default options based on field attributes. | ||
if (!$hideNone) | ||
{ | ||
$options[] = JHtml::_('select.option', '-1', JText::alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $fieldname))); | ||
} | ||
if (!$hideDefault) | ||
{ | ||
$options[] = JHtml::_('select.option', '', JText::alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $fieldname))); | ||
} | ||
|
||
// Get a list of files in the search path with the given filter. | ||
$files = JFolder::files($path, $filter); | ||
|
||
// Build the options list from the list of files. | ||
if (is_array($files)) | ||
{ | ||
foreach ($files as $file) | ||
{ | ||
|
||
// Check to see if the file is in the exclude mask. | ||
if ($exclude) | ||
{ | ||
if (preg_match(chr(1) . $exclude . chr(1), $file)) | ||
{ | ||
continue; | ||
} | ||
} | ||
|
||
// If the extension is to be stripped, do it. | ||
if ($stripExt) | ||
{ | ||
$file = JFile::stripExt($file); | ||
} | ||
|
||
$options[] = JHtml::_('select.option', $file, $file); | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
} |
Oops, something went wrong.