Skip to content

Commit

Permalink
This is a combination of 10 commits.
Browse files Browse the repository at this point in the history
This is the 1st commit message:

First commit which integrates the subform custom field type.

This is the commit message joomla#2:

Rename manifest file for plg_fields_subform

This is the commit message joomla#3:

plg_fields_subform: Improve code comments and made the subform field type optionally non-repeatable.

This is the commit message joomla#4:

Fix not being able to change the type of a subfield.

This is the commit message joomla#5:

Implement a small in-memory renderCache for subform custom fields

This is the commit message joomla#6:

Prepare to load the subfields into a subform custom field directly via their own xml definition.

This is the commit message joomla#7:

After merge with PR joomla#17552 we can now successfully show the subforms options for the different types.

This is the commit message joomla#8:

The subform custom field type doesnt need a default value.

This is the commit message joomla#9:

Implement an option for a subform customfield to disable rendering the field values.

This is the commit message joomla#10:

Remove unused code and set hidden fields to not-required.
  • Loading branch information
infograf768 authored and Rene Pasing committed Sep 24, 2018
1 parent 17c3ec7 commit 9be4118
Show file tree
Hide file tree
Showing 16 changed files with 731 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
(479, 0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -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
(479, 0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -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
(479, 0, 'plg_fields_subform', 'plugin', 'subform', 'fields', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0);
31 changes: 25 additions & 6 deletions administrator/components/com_fields/libraries/fieldsplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,32 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form
* @since 3.7.0
*/
public function onContentPrepareForm(JForm $form, $data)
{
$path = $this->getFormPath($form, $data);
if ($path === null)
{
return;
}
// Load the specific plugin parameters
$form->load(file_get_contents($path), true, '/form/*');
}

/**
* Returns the path of the XML definition file for the field parameters
*
* @param JForm $form The form
* @param stdClass $data The data
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
protected function getFormPath(JForm $form, $data)
{
// Check if the field form is calling us
if (strpos($form->getName(), 'com_fields.field') !== 0)
{
return;
return null;
}

// Ensure it is an object
Expand All @@ -241,19 +262,17 @@ public function onContentPrepareForm(JForm $form, $data)
// Not us
if (!$this->isTypeSupported($type))
{
return;
return null;
}

$path = JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name . '/params/' . $type . '.xml';

// Check if params file exists
if (!file_exists($path))
{
return;
return null;
}

// Load the specific plugin parameters
$form->load(file_get_contents($path), true, '/form/*');
return $path;
}

/**
Expand Down
57 changes: 57 additions & 0 deletions administrator/components/com_fields/models/fields/subformtype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_fields
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;

JFormHelper::loadFieldClass('list');

/**
* Fields Subformtype
*
* @see \JFormFieldType
* @since __DEPLOY_VERSION__
*/
class JFormFieldSubformtype extends JFormFieldList
{
public $type = 'Subformtype';

/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since __DEPLOY_VERSION__
*/
protected function getOptions()
{
$options = parent::getOptions();

$fieldTypes = FieldsHelper::getFieldTypes();

foreach ($fieldTypes as $fieldType)
{
// Skip subform type. We (currently) won't have subforms in subforms.
if ($fieldType['type'] == 'subform')
{
continue;
}
$options[] = JHtml::_('select.option', $fieldType['type'], $fieldType['label']);
}

// Sorting the fields based on the text which is displayed
usort(
$options,
function ($a, $b)
{
return strcmp($a->text, $b->text);
}
);

return $options;
}
}
16 changes: 16 additions & 0 deletions administrator/language/en-GB/en-GB.plg_fields_subform.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Joomla! Project
; Copyright (C) 2005 - 2017 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_SUBFORM="Fields - Subform"
PLG_FIELDS_SUBFORM_XML_DESCRIPTION="This plugin lets you create new fields of type 'subform' in any extensions where custom fields are supported."
PLG_FIELDS_SUBFORM_LABEL="Subform (%s)"
PLG_FIELDS_SUBFORM_PARAMS_OPTIONS_LABEL="Fields"
PLG_FIELDS_SUBFORM_PARAMS_OPTIONS_DESC="The fields of the subform."
PLG_FIELDS_SUBFORM_PARAMS_REPEAT_LABEL="Repeatable"
PLG_FIELDS_SUBFORM_PARAMS_REPEAT_DESC="Whether this subform shall be repeatable."
PLG_FIELDS_SUBFORM_PARAMS_RENDER_VALUES_LABEL="Render values"
PLG_FIELDS_SUBFORM_PARAMS_RENDER_VALUES_DESC="Do you want the custom field plugin to render the values of this subforms fields? Rendering is, for example, unneeded if your subform only contains 'text' fields, because text values does't change when being rendered. But when you e.g. have a 'media' field, the unrendered value will be the url to that media, the rendered value will be a HTML &lt;img&gt;-tag, for example. If you create your own layout override, where you can take care of the unrendered value, you should always disable rendering, as rendering always comes at a cost of performance."
PLG_FIELDS_SUBFORM_PARAMS_OPTIONS_NAME_LABEL="Name"
PLG_FIELDS_SUBFORM_PARAMS_OPTIONS_NAME_DESC="The name to identify the field."
7 changes: 7 additions & 0 deletions administrator/language/en-GB/en-GB.plg_fields_subform.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2017 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_SUBFORM="Fields - Subform"
PLG_FIELDS_SUBFORM_XML_DESCRIPTION="This plugin lets you create new fields of type 'subform' in any extensions where custom fields are supported."
1 change: 1 addition & 0 deletions installation/sql/mysql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `elem
(492, 0, 'plg_privacy_message', 'plugin', 'message', 'privacy', 0, 1, 1, 0, '', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(493, 0, 'plg_privacy_actionlogs', 'plugin', 'actionlogs', 'privacy', 0, 0, 1, 0, '', '{}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(494, 0, 'plg_captcha_recaptcha_invisible', 'plugin', 'recaptcha_invisible', 'captcha', 0, 0, 1, 0, '', '{"public_key":"","private_key":"","theme":"clean"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(495, 0, 'plg_fields_subform', 'plugin', 'subform', '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),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem
(492, 0, 'plg_privacy_message', 'plugin', 'message', 'privacy', 0, 1, 1, 0, '', '{}', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(493, 0, 'plg_privacy_actionlogs', 'plugin', 'actionlogs', 'privacy', 0, 0, 1, 0, '', '{}', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(494, 0, 'plg_captcha_recaptcha_invisible', 'plugin', 'recaptcha_invisible', 'captcha', 0, 0, 1, 0, '', '{"public_key":"","private_key":"","theme":"clean"}', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(495, 0, 'plg_fields_subform', 'plugin', 'subform', '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),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/sqlazure/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem
(492, 0, 'plg_privacy_message', 'plugin', 'user', 'message', 0, 1, 1, 0, '', '{}', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(493, 0, 'plg_privacy_actionlogs', 'plugin', 'actionlogs', 'privacy', 0, 0, 1, 0, '', '{}', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(494, 0, 'plg_captcha_recaptcha_invisible', 'plugin', 'recaptcha_invisible', 'captcha', 0, 0, 1, 0, '', '{"public_key":"","private_key":"","theme":"clean"}', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(495, 0, 'plg_fields_subform', 'plugin', 'subform', '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),
Expand Down
2 changes: 1 addition & 1 deletion media/system/js/subform-repeatable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9be4118

Please sign in to comment.