The Problem:
FlexiFields are rendered(=their display is created) even if they are not displayed.
This in general is not needed* and may cause problems.
* It could be needed for a field to be always rendered to have it make the field have a side-effect, e.g. make a db update or file manipulation.
Maybe the templates should have a hidden position for fields that should be rendered but not displayed.
OR put an option to always render a field even if not displayed.
-- An example where a non-displayed field, causes problems when rendered, is the mini-gallery.
-- This mini-gallery FlexiField when rendered, it adds javascript and css to the header.
-- But the javascript will produce an error because the html of the field is not present (the field is not in the template).
Fix:
Comment out line 100-107 of components/com_flexicontent/classes/flexicontent.fields.php
To prevent them from being always rendered and then
replace at line 289-301:
Code:
for ($i=0; $i < sizeof($items); $i++)
{
foreach ($fbypos as $pos) {
foreach ($pos->fields as $f) {
...
}
}
}
with:
Code:
for ($i=0; $i < sizeof($items); $i++)
{
// 'text' item field is always used by category, render it
if ($view == 'category') {
$field = $items[$i]->fields['text'];
$field = FlexicontentFields::renderField($items[$i], $field, $values, $method='display');
}
// render flexi fields if they are present in the template
foreach ($fbypos as $pos) {
foreach ($pos->fields as $f) {
$field = $items[$i]->fields[$f];
$values = isset($items[$i]->fieldvalues[$field->id]) ? $items[$i]->fieldvalues[$field->id] : array();
$field = FlexicontentFields::renderField($items[$i], $field, $values, $method='display');
if (isset($field->display) && $field->display) {
$items[$i]->positions[$pos->position]->{$f}->id = $field->id;
$items[$i]->positions[$pos->position]->{$f}->name = $field->name;
$items[$i]->positions[$pos->position]->{$f}->label = $field->parameters->get('display_label') ? $field->label : '';
$items[$i]->positions[$pos->position]->{$f}->display = $field->display;
}
}
}
}
I also attach the modified file (
components/com_flexicontent/classes/flexicontent.fields.php for version 1.5.5r607), please TEST and post back if it works and backup the original in case you need to restore it. I will then submit it to bug tracker.
Consider this experimental as it is a major change, e.g. with this modification something may not function properly.