Skip to content

Commit

Permalink
Namespace fields plugins base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed May 22, 2017
1 parent 348cbdb commit c221f00
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* @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;
namespace Joomla\Component\Fields\Administrator\Plugin;

JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR);
defined('_JEXEC') or die;

/**
* Base plugin for all list based plugins
Expand All @@ -20,15 +20,15 @@ class FieldsListPlugin extends FieldsPlugin
/**
* Transforms the field into a DOM XML element and appends it as a child on the given parent.
*
* @param stdClass $field The field.
* @param DOMElement $parent The field node parent.
* @param JForm $form The form.
* @param \stdClass $field The field.
* @param \DOMElement $parent The field node parent.
* @param \JForm $form The form.
*
* @return DOMElement
* @return \DOMElement
*
* @since 3.7.0
*/
public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form)
public function onCustomFieldsPrepareDom($field, \DOMElement $parent, \JForm $form)
{
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form);

Expand All @@ -41,8 +41,8 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form

foreach ($this->getOptionsFromField($field) as $value => $name)
{
$option = new DOMElement('option', htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
$option->nodeValue = htmlspecialchars(JText::_($name), ENT_COMPAT, 'UTF-8');
$option = new \DOMElement('option', htmlspecialchars($value, ENT_COMPAT, 'UTF-8'));
$option->nodeValue = htmlspecialchars(\JText::_($name), ENT_COMPAT, 'UTF-8');

$element = $fieldNode->appendChild($option);
$element->setAttribute('value', $value);
Expand All @@ -54,7 +54,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form
/**
* Returns an array of key values to put in a list from the given field.
*
* @param stdClass $field The field.
* @param \stdClass $field The field.
*
* @return array
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Fields\Administrator\Plugin;

defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;

/**
* Abstract Fields Plugin
*
* @since 3.7.0
*/
abstract class FieldsPlugin extends JPlugin
abstract class FieldsPlugin extends CMSPlugin
{
protected $autoloadLanguage = true;

Expand All @@ -31,7 +36,7 @@ public function onCustomFieldsGetTypes()
// The root of the plugin
$root = JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name;

foreach (JFolder::files($root . '/tmpl', '.php') as $layout)
foreach (\JFolder::files($root . '/tmpl', '.php') as $layout)
{
// Strip the extension
$layout = str_replace('.php', '', $layout);
Expand All @@ -50,12 +55,12 @@ public function onCustomFieldsGetTypes()
// Needed attributes
$data['type'] = $layout;

if (JFactory::getLanguage()->hasKey('PLG_FIELDS_' . $key . '_LABEL'))
if (\JFactory::getLanguage()->hasKey('PLG_FIELDS_' . $key . '_LABEL'))
{
$data['label'] = JText::sprintf('PLG_FIELDS_' . $key . '_LABEL', strtolower($key));
$data['label'] = \JText::sprintf('PLG_FIELDS_' . $key . '_LABEL', strtolower($key));

// Fix wrongly set parentheses in RTL languages
if (JFactory::getLanguage()->isRTL())
if (\JFactory::getLanguage()->isRTL())
{
$data['label'] = $data['label'] . '‎';
}
Expand Down Expand Up @@ -91,9 +96,9 @@ public function onCustomFieldsGetTypes()
/**
* Prepares the field value.
*
* @param string $context The context.
* @param stdclass $item The item.
* @param stdclass $field The field.
* @param string $context The context.
* @param \stdclass $item The item.
* @param \stdclass $field The field.
*
* @return string
*
Expand All @@ -112,7 +117,7 @@ public function onCustomFieldsPrepareField($context, $item, $field)
$fieldParams->merge($field->fieldparams);

// Get the path for the layout file
$path = JPluginHelper::getLayoutPath('fields', $field->type, $field->type);
$path = PluginHelper::getLayoutPath('fields', $field->type, $field->type);

// Render the layout
ob_start();
Expand All @@ -126,23 +131,23 @@ public function onCustomFieldsPrepareField($context, $item, $field)
/**
* Transforms the field into a DOM XML element and appends it as a child on the given parent.
*
* @param stdClass $field The field.
* @param DOMElement $parent The field node parent.
* @param JForm $form The form.
* @param \stdClass $field The field.
* @param \DOMElement $parent The field node parent.
* @param \JForm $form The form.
*
* @return DOMElement
* @return \DOMElement
*
* @since 3.7.0
*/
public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form)
public function onCustomFieldsPrepareDom($field, \DOMElement $parent, \JForm $form)
{
// Check if the field should be processed by us
if (!$this->isTypeSupported($field->type))
{
return null;
}

$app = JFactory::getApplication();
$app = \JFactory::getApplication();

// Detect if the field should be shown at all
if ($field->params->get('show_on') == 1 && $app->isClient('administrator'))
Expand All @@ -155,7 +160,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form
}

// Create the node
$node = $parent->appendChild(new DOMElement('field'));
$node = $parent->appendChild(new \DOMElement('field'));

// Set the attributes
$node->setAttribute('name', $field->name);
Expand Down Expand Up @@ -189,7 +194,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form
}

// Check if it is allowed to edit the field
if (!FieldsHelper::canEditFieldValue($field))
if (!\FieldsHelper::canEditFieldValue($field))
{
$node->setAttribute('disabled', 'true');
}
Expand All @@ -202,14 +207,14 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form
* The form event. Load additional parameters when available into the field form.
* Only when the type of the form is of interest.
*
* @param JForm $form The form
* @param stdClass $data The data
* @param \JForm $form The form
* @param \stdClass $data The data
*
* @return void
*
* @since 3.7.0
*/
public function onContentPrepareForm(JForm $form, $data)
public function onContentPrepareForm(\JForm $form, $data)
{
// Check if the field form is calling us
if (strpos($form->getName(), 'com_fields.field') !== 0)
Expand Down

0 comments on commit c221f00

Please sign in to comment.