diff --git a/administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-05-19.sql b/administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-05-19.sql new file mode 100644 index 0000000000000..512acbd7f707e --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-05-19.sql @@ -0,0 +1,2 @@ +INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES +(481, 0, 'plg_fields_repeatable', 'plugin', 'repeatable', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0); diff --git a/administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-05-19.sql b/administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-05-19.sql new file mode 100644 index 0000000000000..b8ce724e76bf4 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-05-19.sql @@ -0,0 +1,2 @@ +INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES +(481, 0, 'plg_fields_repeatable', 'plugin', 'repeatable', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0); diff --git a/administrator/components/com_admin/sql/updates/sqlazure/3.9.0-2018-05-19.sql b/administrator/components/com_admin/sql/updates/sqlazure/3.9.0-2018-05-19.sql new file mode 100644 index 0000000000000..3536e787202f0 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/sqlazure/3.9.0-2018-05-19.sql @@ -0,0 +1,2 @@ +INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES +(481, 0, 'plg_fields_repeatable', 'plugin', 'repeatable', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0); diff --git a/administrator/language/en-GB/en-GB.plg_fields_repeatable.ini b/administrator/language/en-GB/en-GB.plg_fields_repeatable.ini new file mode 100644 index 0000000000000..b9b6200ec2ebf --- /dev/null +++ b/administrator/language/en-GB/en-GB.plg_fields_repeatable.ini @@ -0,0 +1,18 @@ +; Joomla! Project +; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_FIELDS_REPEATABLE="Fields - Repeatable" +PLG_FIELDS_REPEATABLE_LABEL="Repeatable (%s)" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_NAME_DESC="The name of the field to display in the form" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_NAME_LABEL="Name" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_TYPE_DESC="Set the field type" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_TYPE_EDITOR="Editor" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_TYPE_LABEL="Type" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_TYPE_MEDIA="Media" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_TYPE_NUMBER="Number" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_TYPE_TEXT="Text" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDNAME_TYPE_TEXTAREA="Text Area" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDS_DESC="Add one or more form fields" +PLG_FIELDS_REPEATABLE_PARAMS_FIELDS_LABEL="Form Fields" diff --git a/administrator/language/en-GB/en-GB.plg_fields_repeatable.sys.ini b/administrator/language/en-GB/en-GB.plg_fields_repeatable.sys.ini new file mode 100644 index 0000000000000..8d4d8a4610b2c --- /dev/null +++ b/administrator/language/en-GB/en-GB.plg_fields_repeatable.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_FIELDS_REPEATABLE="Fields - Repeatable" +PLG_FIELDS_REPEATABLE_XML_DESCRIPTION="Plugin to create a repeatable form with customizable fields" diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 764e32d3af954..4e80613e403e8 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -643,6 +643,7 @@ INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `elem (478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), (479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), (480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), +(481, 0, 'plg_fields_repeatable', 'plugin', 'repeatable', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), (503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '0000-00-00 00:00:00', 0, 0), (504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0), (506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0), diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index 42f10d6b6d255..6fff15ed52447 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -657,6 +657,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem (478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0), (479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0), (480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0), +(481, 0, 'plg_fields_repeatable', 'plugin', 'repeatable', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0), (503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1970-01-01 00:00:00', 0, 0), (504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '1970-01-01 00:00:00', 0, 0), (506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '1970-01-01 00:00:00', 0, 0), diff --git a/installation/sql/sqlazure/joomla.sql b/installation/sql/sqlazure/joomla.sql index 0bc5b3c0db071..14ed187c8cf7e 100644 --- a/installation/sql/sqlazure/joomla.sql +++ b/installation/sql/sqlazure/joomla.sql @@ -872,6 +872,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem (478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0), (479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0), (480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0), +(481, 0, 'plg_fields_repeatable', 'plugin', 'repeatable', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0), (503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1900-01-01 00:00:00', 0, 0), (504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '1900-01-01 00:00:00', 0, 0), (506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '1900-01-01 00:00:00', 0, 0), diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php index 373fd1b6f6bee..e1e4baf3bba0c 100644 --- a/libraries/src/Extension/ExtensionHelper.php +++ b/libraries/src/Extension/ExtensionHelper.php @@ -176,6 +176,7 @@ class ExtensionHelper array('plugin', 'list', 'fields', 0), array('plugin', 'media', 'fields', 0), array('plugin', 'radio', 'fields', 0), + array('plugin', 'repeatable', 'fields', 0), array('plugin', 'sql', 'fields', 0), array('plugin', 'text', 'fields', 0), array('plugin', 'textarea', 'fields', 0), diff --git a/plugins/fields/repeatable/params/repeatable.xml b/plugins/fields/repeatable/params/repeatable.xml new file mode 100644 index 0000000000000..9866980cf37c8 --- /dev/null +++ b/plugins/fields/repeatable/params/repeatable.xml @@ -0,0 +1,38 @@ + +
+ +
+ + + +
+ + + + + + + + +
+
+ +
+
+
+ diff --git a/plugins/fields/repeatable/repeatable.php b/plugins/fields/repeatable/repeatable.php new file mode 100644 index 0000000000000..bceb02ee1c13e --- /dev/null +++ b/plugins/fields/repeatable/repeatable.php @@ -0,0 +1,143 @@ +setAttribute('type', 'subform'); + $fieldNode->setAttribute('multiple', 'true'); + $fieldNode->setAttribute('layout', 'joomla.form.field.subform.repeatable-table'); + + // Build the form source + $fieldsXml = new SimpleXMLElement('
'); + $fields = $fieldsXml->addChild('fields'); + + // Get the form settings + $formFields = $field->fieldparams->get('fields'); + + // Add the fields to the form + foreach ($formFields as $index => $formField) + { + $child = $fields->addChild('field'); + $child->addAttribute('name', $formField->fieldname); + $child->addAttribute('type', $formField->fieldtype); + $child->addAttribute('readonly', $readonly); + } + + $fieldNode->setAttribute('formsource', $fieldsXml->asXML()); + + // Return the node + return $fieldNode; + } + + /** + * The save event. + * + * @param string $context The context + * @param JTable $item The article data + * @param boolean $isNew Is new item + * @param array $data The validated data + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function onContentAfterSave($context, $item, $isNew, $data = array()) + { + // Create correct context for category + if ($context == 'com_categories.category') + { + $context = $item->get('extension') . '.categories'; + + // Set the catid on the category to get only the fields which belong to this category + $item->set('catid', $item->get('id')); + } + + // Check the context + $parts = FieldsHelper::extract($context, $item); + + if (!$parts) + { + return true; + } + + // Compile the right context for the fields + $context = $parts[0] . '.' . $parts[1]; + + // Loading the fields + $fields = FieldsHelper::getFields($context, $item); + + if (!$fields) + { + return true; + } + + // Get the fields data + $fieldsData = !empty($data['com_fields']) ? $data['com_fields'] : array(); + + // Loading the model + /** @var FieldsModelField $model */ + $model = BaseDatabaseModel::getInstance('Field', 'FieldsModel', array('ignore_request' => true)); + + // Loop over the fields + foreach ($fields as $field) + { + // Find the field of this type repeatable + if ($field->type !== $this->_name) + { + continue; + } + + // Determine the value if it is available from the data + $value = key_exists($field->name, $fieldsData) ? $fieldsData[$field->name] : null; + + // Setting the value for the field and the item + $model->setFieldValue($field->id, $item->get('id'), json_encode($value)); + } + + return true; + } +} diff --git a/plugins/fields/repeatable/repeatable.xml b/plugins/fields/repeatable/repeatable.xml new file mode 100644 index 0000000000000..6de3f0705e5d3 --- /dev/null +++ b/plugins/fields/repeatable/repeatable.xml @@ -0,0 +1,21 @@ + + + plg_fields_repeatable + Joomla! Project + April 2018 + Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + __DEPLOY_VERSION__ + PLG_FIELDS_REPEATABLE_XML_DESCRIPTION + + repeatable.php + params + tmpl + + + en-GB/en-GB.plg_fields_repeatable.ini + en-GB/en-GB.plg_fields_repeatable.sys.ini + + diff --git a/plugins/fields/repeatable/tmpl/repeatable.php b/plugins/fields/repeatable/tmpl/repeatable.php new file mode 100644 index 0000000000000..c05a04a94a6da --- /dev/null +++ b/plugins/fields/repeatable/tmpl/repeatable.php @@ -0,0 +1,36 @@ +value; + +if ($fieldValue === '') +{ + return; +} + +// Get the values +$fieldValues = json_decode($fieldValue, true); + +if (empty($fieldValues)) +{ + return; +} + +$html = ''; + +echo $html;