FieldsPlugin subform

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Gulvar
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Sep 07, 2017 1:10 pm

FieldsPlugin subform

Postby Gulvar » Tue Jan 16, 2018 4:39 pm

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/tmpl/slides.php

Code: Select all

<?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

Code: Select all

<?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>


Some screenshots :
Screenshot from 2018-01-16 17-35-04.png

Screenshot from 2018-01-16 17-37-16.png

Screenshot from 2018-01-16 17-37-43.png
You do not have the required permissions to view the files attached to this post.

Gulvar
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Sep 07, 2017 1:10 pm

Re: FieldsPlugin subform

Postby Gulvar » Wed Jan 17, 2018 9:59 am

Errata : the code given was from the file plugins/fields/slides/slides.php not plugins/fields/slides/tmpl/slides.php

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 ?


Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: No registered users and 3 guests