Gulvar
unread,Jan 17, 2018, 11:55:34 AM1/17/18Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Joomla! General Development
Hi everybody.
I try to create a FieldsPlugin with a repeatable subform. The display works great but the storage in database does not work.
Here's my plugin structure :
plugins/fields/slides/slides.xml
plugins/fields/slides/subform.xml (contains the subform to repeat)
plugins/fields/slides/tmpl/slides.php (just a hello world for the moment)
plugins/fields/slides/params/slides.xml (standard field plugin params)
The plugin is installed and works, I can choose the type "slides" when I create a custom field.
My repeatable subform shows well on the content form page.
When I save my form there are same amount of lines added in #__fields_values as the amount of lines of repeatable subform I created the field_id and item_id are correct but the value column is empty.
I suppose that the framework doesn't test the type of "value" before sending it the database. So it send the Array() (PHP) and that cause a blank value in the database.
Anybody here already tries to make something similar ? Any advice ?
Thanks for help.
My code :
plugins/fields/slides/slides.php
------------------------------------------------------
<?php
defined('_JEXEC') or die;
JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR);
class PlgFieldsSlides extends FieldsPlugin
{
public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form) {
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form);
if (!$fieldNode) {
return $fieldNode;
}
$fieldNode->setAttribute('type', 'subform');
$fieldNode->setAttribute('formsource', "plugins/fields/slides/subform.xml");
$fieldNode->setAttribute('multiple', 'true');
$fieldNode->setAttribute('layout', 'joomla.form.field.subform.repeatable-table');
return $fieldNode;
}
}
----------------------------------------------------------
plugins/fields/slides/subform.xml
----------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="section1" label="Section1">
<field name="title" type="text" label="Title" required="true"/>
<field name="slide" type="media" label="Image" required="true"/>
</fieldset>
</form>
----------------------------------------------------------
PS : To test I made a verification in the onContentAfterSave function on the file plugins/system/fields/fields.php
Something to detect if the value type is an array (or object) and serialize it.
It works, the value in database are correctly set.
But I can't change the official plugin.
Does anybody knows a way to manipulate the value in a fields plugin before it is saved by the system plugin ?