Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[com_fields] Fix fields display HTML prepared 4 or 5 times per article, make it be prepared only twice #17895

Merged
merged 9 commits into from
Mar 29, 2018
5 changes: 3 additions & 2 deletions administrator/components/com_fields/helpers/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function extract($contextString, $item = null)
*
* @param string $context The context of the content passed to the helper
* @param stdClass $item item
* @param boolean $prepareValue prepareValue
* @param int|bool $prepareValue (if int is display event): 1 - AfterTitle, 2 - BeforeDisplay, 3 - AfterDisplay, 0 - OFF
* @param array $valuesToOverride The values to override
*
* @return array
Expand Down Expand Up @@ -187,7 +187,8 @@ function ($f)

$field->rawvalue = $field->value;

if ($prepareValue)
// If boolean prepare, if int, it is the event type: 1 - After Title, 2 - Before Display, 3 - After Display, 0 - Do not prepare
if ($prepareValue && (is_bool($prepareValue) || $prepareValue === (int) $field->params->get('display', '2')))
{
JPluginHelper::importPlugin('fields');

Expand Down
10 changes: 9 additions & 1 deletion plugins/system/fields/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private function display($context, $item, $params, $displayType)
$params = new Registry($params);
}

$fields = FieldsHelper::getFields($context, $item, true);
$fields = FieldsHelper::getFields($context, $item, $displayType);

if ($fields)
{
Expand Down Expand Up @@ -450,6 +450,12 @@ private function display($context, $item, $params, $displayType)
*/
public function onContentPrepare($context, $item)
{
// Check property exists (avoid costly & useless recreation), if need to recreate them, just unset the property!
if (isset($item->jcfields))
{
return;
}

$parts = FieldsHelper::extract($context, $item);

if (!$parts)
Expand All @@ -468,6 +474,8 @@ public function onContentPrepare($context, $item)
$item = $this->prepareTagItem($item);
}

// Get item's fields, also preparing their value property for manual display
// (calling plugins events and loading layouts to get their HTML display)
$fields = FieldsHelper::getFields($context, $item, true);

// Adding the fields to the object
Expand Down