Skip to content

Commit

Permalink
Store fields in 'com_fields' property instead of reusing 'params'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hunziker committed Dec 14, 2016
1 parent 6bdd0ef commit 21ebe41
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 58 deletions.
8 changes: 4 additions & 4 deletions administrator/components/com_fields/helpers/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function extract($contextString)
* Should the value being prepared to be shown in an HTML context then
* prepareValue must be set to true. No further escaping needs to be done.
* The values of the fields can be overridden by an associative array where the keys
* can be an id or an alias and it's corresponding value.
* has to be an id or and it's corresponding value.
*
* @param string $context The context of the content passed to the helper
* @param stdClass $item item
Expand Down Expand Up @@ -326,7 +326,7 @@ public static function prepareForm($context, JForm $form, $data)
// Creating the dom
$xml = new DOMDocument('1.0', 'UTF-8');
$fieldsNode = $xml->appendChild(new DOMElement('form'))->appendChild(new DOMElement('fields'));
$fieldsNode->setAttribute('name', 'params');
$fieldsNode->setAttribute('name', 'com_fields');

// Organizing the fields according to their group
$fieldsPerGroup = array(
Expand Down Expand Up @@ -478,7 +478,7 @@ public static function prepareForm($context, JForm $form, $data)
if (!is_array($value) && $value !== '')
{
// Function getField doesn't cache the fields, so we try to do it only when necessary
$formField = $form->getField($field->id, 'params');
$formField = $form->getField($field->id, 'com_fields');

if ($formField && $formField->forceMultiple)
{
Expand All @@ -487,7 +487,7 @@ public static function prepareForm($context, JForm $form, $data)
}

// Setting the value on the field
$form->setValue($field->id, 'params', $value);
$form->setValue($field->id, 'com_fields', $value);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion components/com_contact/controllers/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private function _sendEmail($data, $contact, $copy_email_activated)
$body = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body);

// Load the custom fields
if ($data['params'] && $fields = FieldsHelper::getFields('com_contact.mail', $contact, true, $data['params']))
if ($data['com_fields'] && $fields = FieldsHelper::getFields('com_contact.mail', $contact, true, $data['com_fields']))
{
$output = FieldsHelper::render(
'com_contact.mail',
Expand Down
4 changes: 2 additions & 2 deletions libraries/joomla/form/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,11 +1082,11 @@ public function appendXMLFieldTag($field, DOMElement $parent, JForm $form)
{
$app = JFactory::getApplication();

if ($field->params->get('show_on') == 1 && $app->isAdmin())
if ($field->params->get('show_on') == 1 && $app->isClient('administrator'))
{
return;
}
elseif ($field->params->get('show_on') == 2 && $app->isSite())
elseif ($field->params->get('show_on') == 2 && $app->isClient('site'))
{
return;
}
Expand Down
58 changes: 7 additions & 51 deletions plugins/system/fields/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,24 @@ public function onContentBeforeSave($context, $item, $isNew)
return true;
}

$params = new Registry;

// Load the item params from the request
// Load the fields data from the request
$data = JFactory::getApplication()->input->post->get('jform', array(), 'array');

if (key_exists('params', $data))
{
$params->loadArray($data['params']);
}

// Load the params from the item itself
if (isset($item->params))
if (!key_exists('com_fields', $data))
{
$params->loadString($item->params);
return true;
}

$params = $params->toArray();

// Create the new internal fields field
$fields = array();
$item->_fields = array();

foreach ($fieldsObjects as $field)
{
// Set the param on the fields variable
$fields[$field->id] = key_exists($field->id, $params) ? $params[$field->id] : array();

// Remove it from the params array
unset($params[$field->id]);
// Set the field data on the fields variable
$item->_fields[$field->id] = key_exists($field->id, $data['com_fields']) ? $data['com_fields'][$field->id] : array();
}

$item->_fields = $fields;

// Update the cleaned up params
if (isset($item->params))
{
$item->params = json_encode($params);
}
unset ($data['com_fields']);

return true;
}
Expand Down Expand Up @@ -300,31 +281,6 @@ public function onContentPrepareForm(JForm $form, $data)
return true;
}

/**
* The prepare data event.
*
* @param string $context The context
* @param stdClass $data The data
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onContentPrepareData($context, $data)
{
$parts = $this->getParts($context);

if (!$parts)
{
return;
}

if (isset($data->params) && $data->params instanceof Registry)
{
$data->params = $data->params->toArray();
}
}

/**
* The display event.
*
Expand Down

0 comments on commit 21ebe41

Please sign in to comment.