diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index afbc2cefafbd0..52c9c46c19136 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -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 @@ -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'); diff --git a/plugins/system/fields/fields.php b/plugins/system/fields/fields.php index 746f689f5eedb..b142067da281b 100644 --- a/plugins/system/fields/fields.php +++ b/plugins/system/fields/fields.php @@ -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) { @@ -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) @@ -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