User tests: Successful: Unsuccessful:
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.
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));
See field value in all categories, extra database query for fields load without filter.assigned_cat_ids
model state.
Field value only in field-specific category, all events for the category text are using the single load of fields for this category.
Status | New | ⇒ | Pending |
Category | ⇒ | Front End Plugins |
Title |
|
Title |
|
The same code already exists...
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-10-23 07:45:05 |
Closed_By | ⇒ | HLeithner | |
Labels |
Added:
?
|
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
I'm not sure if it is wise to modify the object properties in the event.