? Pending

User tests: Successful: Unsuccessful:

avatar Denitz
Denitz
20 Oct 2022

Summary of Changes

Auto-add catid property for com_xxx.categories context on onContentPrepare event.

It's already done in PlgSystemFields::onContentAfterTitle(), PlgSystemFields::onContentBeforeDisplay() and , PlgSystemFields::onContentAfterDisplay() which all use PlgSystemFields::display() method with:

        // If we have a category, set the catid field to fetch only the fields which belong to it
        if ($parts[1] === 'categories' && !isset($item->catid)) {
            $item->catid = $item->id;
        }

Otherwise, FieldsHelper::getFields() doesn't apply filter.assigned_cat_ids state on fields model, it results on extra database query and actually all fields applied in this event.

Testing Instructions

Assign custom field to only specific category, insert field value into category description.

Also test database queries for blog articles layout when category description is displayed and there are category custom fields.

See 4 events triggered on the category in components/com_content/tmpl/category/blog.php, they should all use the single fields load while actually we have too because the onContentPrepare event is not loading fields with filter.assigned_cat_ids model state:

$this->category->text = $this->category->description;
$app->triggerEvent('onContentPrepare', array($this->category->extension . '.categories', &$this->category, &$this->params, 0));
$this->category->description = $this->category->text;

$results = $app->triggerEvent('onContentAfterTitle', array($this->category->extension . '.categories', &$this->category, &$this->params, 0));
$afterDisplayTitle = trim(implode("\n", $results));

$results = $app->triggerEvent('onContentBeforeDisplay', array($this->category->extension . '.categories', &$this->category, &$this->params, 0));
$beforeDisplayContent = trim(implode("\n", $results));

$results = $app->triggerEvent('onContentAfterDisplay', array($this->category->extension . '.categories', &$this->category, &$this->params, 0));
$afterDisplayContent = trim(implode("\n", $results));

Actual result BEFORE applying this Pull Request

See field value in all categories, extra database query for fields load without filter.assigned_cat_ids model state.

Expected result AFTER applying this Pull Request

Field value only in field-specific category, all events for the category text are using the single load of fields for this category.

avatar Denitz Denitz - open - 20 Oct 2022
avatar Denitz Denitz - change - 20 Oct 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 20 Oct 2022
Category Front End Plugins
avatar Denitz Denitz - change - 20 Oct 2022
Title
onContentPrepare for com_xxx.categories context doesn't load category…
onContentPrepare for com_xxx.categories fields load
avatar Denitz Denitz - edited - 20 Oct 2022
avatar Denitz Denitz - change - 20 Oct 2022
Title
onContentPrepare for com_xxx.categories fields load
onContentPrepare for com_xxx.categories custom fields load
avatar Denitz Denitz - edited - 20 Oct 2022
avatar laoneo
laoneo - comment - 20 Oct 2022

I'm not sure if it is wise to modify the object properties in the event.

avatar Denitz
Denitz - comment - 20 Oct 2022

The same code already exists...

avatar HLeithner HLeithner - change - 23 Oct 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-10-23 07:45:05
Closed_By HLeithner
Labels Added: ?
avatar HLeithner
HLeithner - comment - 23 Oct 2022

Hi,

maintainers talked about it and think it would be better make custom fields more category aware (checking in the fields helper and not adding a field to the object).

I'm closing this for now, if you have a better solution you can reopen it.
thanks

avatar HLeithner HLeithner - close - 23 Oct 2022

Add a Comment

Login with GitHub to post a comment