FieldsPlugin subform

71 views
Skip to first unread message

Gulvar

unread,
Jan 17, 2018, 11:55:34 AM1/17/18
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 ?

Allon Moritz

unread,
Jan 18, 2018, 1:59:52 AM1/18/18
to joomla-de...@googlegroups.com
Do you have a Github repo where we can see the code, perhaps I can give you a hint.


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send an email to joomla-dev-general@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Gulvar

unread,
Jan 18, 2018, 4:15:27 AM1/18/18
to Joomla! General Development
Thanks for your reply.
Here it is : https://bitbucket.org/sebastien_horemans/plg_slides/src

Thanks for your help.
To post to this group, send an email to joomla-de...@googlegroups.com.

pepperstreet

unread,
Jul 11, 2018, 8:37:16 PM7/11/18
to Joomla! General Development

Does anybody knows a way to manipulate the value in a fields plugin before it is saved by the system plugin ?

Hello, maybe this related product and author can be of any help for you? 
 
Reply all
Reply to author
Forward
0 new messages