Hello,
While trying to work with auto-relations, I have seen that the code to display the button to create the new item is missing from the reverse relation plugin.
On my point of view, the currently displayed item has a reverse relation field corresponding to the relation field of the new item. So, the "add related item" button should be displayed by the reverse relation, but there was no code for that in the reverse relation plugin.
To achieve this, I have done the following changes :
I have added the needed parameters to the XML file by changing :
Code:
<field name="closetag" type="text" default="" label="FLEXI_FIELD_CLOSING_TEXT" description="FLEXI_FIELD_CLOSING_TEXT_DESC" />
</fieldset>
to
Code:
<field name="closetag" type="text" default="" label="FLEXI_FIELD_CLOSING_TEXT" description="FLEXI_FIELD_CLOSING_TEXT_DESC" />
<field name="" type="separator" default="FLEXI_RIFLD_AUTORELATE_SUBMISSION" description="FLEXI_RIFLD_AUTORELATE_SUBMISSION_DESC" hr="false" level="level1" menu="hide" />
<field name="auto_relate_curritem" type="radio" default="0" label="FLEXI_RIFLD_AUTORELATE_SHOW_SUBMIT_BUTTON" description="FLEXI_RIFLD_AUTORELATE_SHOW_SUBMIT_BUTTON_DESC">
<option value="0">FLEXI_NO</option>
<option value="1">FLEXI_YES</option>
</field>
<field name="auto_relate_submit_text" type="text" default="" label="FLEXI_RIFLD_AUTORELATE_SUBMIT_BUTTON_TEXT" description="FLEXI_RIFLD_AUTORELATE_SUBMIT_BUTTON_TEXT_DESC" />
<field name="auto_relate_position" type="radio" default="0" label="FLEXI_RIFLD_AUTORELATE_POSITION" description="FLEXI_RIFLD_AUTORELATE_POSITION_DESC">
<option value="0">FLEXI_BEFORE</option>
<option value="1">FLEXI_AFTER</option>
<option value="2">FLEXI_BOTH</option>
</field>
<field name="auto_relate_menu_itemid" type="text" multiple="false" label="FLEXI_RIFLD_AUTORELATE_SUBMIT_MENU_ITEMID" description="FLEXI_RIFLD_AUTORELATE_SUBMIT_MENU_ITEMID_DESC" />
<field name="auto_relate_show_to_unauth" type="list" default="0" label="FLEXI_RIFLD_AUTORELATE_SHOW_TO_UNLOGGED" description="FLEXI_RIFLD_AUTORELATE_SHOW_TO_UNLOGGED_DESC">
<option value="0">FLEXI_NO</option>
<option value="1">FLEXI_YES_EXCLUDE_GUESTS</option>
<option value="2">FLEXI_YES</option>
</field>
</fieldset>
and changing this in the PHP file :
Code:
$_itemids_catids[$itemid]->value = $val;
}
}
$field->{$prop} = FlexicontentFields::getItemsList($field->parameters, $_itemids_catids, $isform=0, @ $reverse_field, $field, $item);
}
to
Code:
$_itemids_catids[$itemid]->value = $val;
}
}
// **********************************************
// Create the submit button for auto related item
// **********************************************
$auto_relate_curritem = $field->parameters->get( 'auto_relate_curritem', 0);
$auto_relate_menu_itemid = $field->parameters->get( 'auto_relate_menu_itemid', 0);
$auto_relate_position = $field->parameters->get( 'auto_relate_position', 0);
$auto_rel_btn = '';
if ( $auto_relate_curritem && $auto_relate_menu_itemid && (!$display_total || $total_show_auto_btn) )
{
$_submit_text = $field->parameters->get( 'auto_relate_submit_text', 'FLEXI_ADD_RELATED');
$_show_to_unauth = $field->parameters->get( 'auto_relate_show_to_unauth', 0);
$auto_relations[0] = new stdClass();
$auto_relations[0]->itemid = $item->id;
$auto_relations[0]->fieldid = $reverse_field;
$category = null;
$auto_rel_btn = flexicontent_html::addbutton(
$field->parameters, $category, $auto_relate_menu_itemid, $_submit_text, $auto_relations, $_show_to_unauth
);
}
// *****************************
// Finally, create the item list
// *****************************
$add_before = $auto_rel_btn && ($auto_relate_position == 0 || $auto_relate_position == 2);
$add_after = $auto_rel_btn && ($auto_relate_position == 1 || $auto_relate_position == 2);
$field->{$prop} .= ''
.($add_before ? $auto_rel_btn : '')
.FlexicontentFields::getItemsList($field->parameters, $_itemids_catids, $isform=0, @ $reverse_field, $field, $item)
.($add_after ? $auto_rel_btn : '');
}
I have also change the following code in the start of the PHP file :
Code:
function plgFlexicontent_fieldsRelation_reverse( &$subject, $params )
{
parent::__construct( $subject, $params );
JPlugin::loadLanguage('plg_flexicontent_fields_relation_reverse', JPATH_ADMINISTRATOR);
}
to
Code:
function plgFlexicontent_fieldsRelation_reverse( &$subject, $params )
{
parent::__construct( $subject, $params );
JPlugin::loadLanguage('plg_flexicontent_fields_relation_reverse', JPATH_ADMINISTRATOR);
JPlugin::loadLanguage('plg_flexicontent_fields_relation', JPATH_ADMINISTRATOR);
}
to avoid duplicating the language constants used.
The code blocks used have been taken from the relation field plugin, thanks to their original author.
The only change done in them is retrieving of the relation field id which is :
Code:
$auto_relations[0] = new stdClass();
$auto_relations[0]->itemid = $item->id;
$auto_relations[0]->fieldid = $field->id;
in the relation field plugin and is :
Code:
$auto_relations[0] = new stdClass();
$auto_relations[0]->itemid = $item->id;
$auto_relations[0]->fieldid = $reverse_field;
in the reverse relation field plugin.
I hope this may help people who want to use this feature.