forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[com_fields] Add base list plugin class which activates the list plug…
…in (joomla#13546) * Add base list plugin class * Update fieldslistplugin.php
- Loading branch information
Showing
6 changed files
with
92 additions
and
72 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
administrator/components/com_fields/libraries/fieldslistplugin.php
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,82 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_fields | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
defined('_JEXEC') or die; | ||
|
||
JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); | ||
|
||
/** | ||
* Base plugin for all list based plugins | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class FieldsListPlugin extends FieldsPlugin | ||
{ | ||
/** | ||
* Transforms the field into an XML element and appends it as child on the given parent. This | ||
* is the default implementation of a field. Form fields which do support to be transformed into | ||
* an XML Element mut implemet the JFormDomfieldinterface. | ||
* | ||
* @param stdClass $field The field. | ||
* @param DOMElement $parent The field node parent. | ||
* @param JForm $form The form. | ||
* | ||
* @return DOMElement | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form) | ||
{ | ||
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); | ||
|
||
if (!$fieldNode) | ||
{ | ||
return $fieldNode; | ||
} | ||
|
||
foreach ($this->getOptionsFromField($field) as $value => $name) | ||
{ | ||
$option = new DOMElement('option', $value); | ||
$option->nodeValue = JText::_($name); | ||
|
||
$element = $fieldNode->appendChild($option); | ||
$element->setAttribute('value', $value); | ||
} | ||
|
||
return $fieldNode; | ||
} | ||
|
||
/** | ||
* Returns an array of key values to put in a list from the given field. | ||
* | ||
* @param stdClass $field The field. | ||
* | ||
* @return array | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function getOptionsFromField($field) | ||
{ | ||
$data = array(); | ||
|
||
// Fetch the options from the plugin | ||
foreach ($this->params->get('options', array()) as $option) | ||
{ | ||
$op = (object) $option; | ||
$data[$op->value] = $op->name; | ||
} | ||
|
||
// Fetch the options from the field | ||
foreach ($field->fieldparams->get('options', array()) as $option) | ||
{ | ||
$data[$option->value] = $option->name; | ||
} | ||
|
||
return $data; | ||
} | ||
} |
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
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