From b2c4d4eefb13ac3f00604937ba92365cea8f76af Mon Sep 17 00:00:00 2001 From: Allon Moritz Date: Sun, 25 Mar 2018 16:55:02 +0200 Subject: [PATCH 01/10] [com_fields] Normalise the request com_fields data (#19884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Normalise the request com_fields data * CS * PHP 5.3 compat * Fields in com_fields array (#9) Fields should be set in com_fields array and not direcly in $data * Spelling * Also normalise request data on front-end user profile save (#10) * Also normalise request data on front-end user profile save * correct context and option * Handle 0 properly in empty check * Simplify * allowing value 0 to be saved (#11) when setting a value of 0 in a text field the function empty will return true > setting the value to null * correct needsUpdate when strlen (or count) = 1 which incorrectly equa… (#12) * correct needsUpdate when strlen (or count) = 1 which incorrectly equaled to 'true' * Update field.php * Update field.php From 8c8735227b9a33632953a4f0de63ee3de3e206f1 Mon Sep 17 00:00:00 2001 From: ruud68 Date: Tue, 3 Apr 2018 14:42:52 +0200 Subject: [PATCH 02/10] Custom fields view on form via toggle on read-only rights --- .../components/com_fields/helpers/fields.php | 28 +++++++++++++++++++ .../com_fields/libraries/fieldsplugin.php | 6 ++++ .../com_fields/models/forms/field.xml | 12 ++++++++ .../com_fields/models/forms/group.xml | 20 +++++++++++-- .../components/com_fields/models/group.php | 12 ++++++++ .../components/com_fields/models/groups.php | 28 +++++++++++++++++++ administrator/language/en-GB/en-GB.ini | 2 ++ 7 files changed, 106 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index 52c9c46c19136..5061150df36e6 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -542,6 +542,34 @@ public static function canEditFieldValue($field) return JFactory::getUser()->authorise('core.edit.value', $parts[0] . '.field.' . (int) $field->id); } + /** + * Return a boolean based on field and field group display read-only setting + * + * @param stdClass $field The field + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public static function displayReadOnlyFieldOnForm($field) + { + if (!JFactory::getApplication()->isClient('administrator') || !$user->authorise('core.admin')) + { + $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); + $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); + $fieldDisplayReadOnly = $field->params->get('display_readonly', '1'); + + if (($groupDisplayReadOnly == 0 || $fieldDisplayReadOnly == 0) && !FieldsHelper::canEditFieldValue($field)) + { + // Do not display field on form when field is read-only + return false; + } + } + + // Display field on form even when field is read-only + return true; + } + /** * Adds Count Items for Category Manager. * diff --git a/administrator/components/com_fields/libraries/fieldsplugin.php b/administrator/components/com_fields/libraries/fieldsplugin.php index 9cf4eb6bb3e36..1d403f331c634 100644 --- a/administrator/components/com_fields/libraries/fieldsplugin.php +++ b/administrator/components/com_fields/libraries/fieldsplugin.php @@ -164,6 +164,12 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form return null; } + // Detect if the field is configured to be displayed on the form based on field / group display read-only setting + if (!FieldsHelper::displayReadOnlyFieldOnForm($field)) + { + return null; + } + // Create the node $node = $parent->appendChild(new DOMElement('field')); diff --git a/administrator/components/com_fields/models/forms/field.xml b/administrator/components/com_fields/models/forms/field.xml index 17de81827a690..6639c8410d635 100644 --- a/administrator/components/com_fields/models/forms/field.xml +++ b/administrator/components/com_fields/models/forms/field.xml @@ -287,6 +287,18 @@ + + + + + diff --git a/administrator/components/com_fields/models/forms/group.xml b/administrator/components/com_fields/models/forms/group.xml index 03a6619019378..4ed5c46842c27 100644 --- a/administrator/components/com_fields/models/forms/group.xml +++ b/administrator/components/com_fields/models/forms/group.xml @@ -89,8 +89,8 @@ filter="user_utc" /> - + + +
+ + + + +
+
diff --git a/administrator/components/com_fields/models/group.php b/administrator/components/com_fields/models/group.php index d8f8c087ed470..cf9147f815af4 100644 --- a/administrator/components/com_fields/models/group.php +++ b/administrator/components/com_fields/models/group.php @@ -8,6 +8,8 @@ */ defined('_JEXEC') or die; +use Joomla\Registry\Registry; + /** * Group Model * @@ -69,6 +71,11 @@ public function save($data) */ public function getTable($name = 'Group', $prefix = 'FieldsTable', $options = array()) { + if (strpos(JPATH_COMPONENT, 'com_fields') === false) + { + $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_fields/tables'); + } + return JTable::getInstance($name, $prefix, $options); } @@ -314,6 +321,11 @@ public function getItem($pk = null) $item->context = $this->getState('filter.context'); } + if (property_exists($item, 'params')) + { + $item->params = new Registry($item->params); + } + // Convert the created and modified dates to local user time for display in the form. $tz = new DateTimeZone(JFactory::getApplication()->get('offset')); diff --git a/administrator/components/com_fields/models/groups.php b/administrator/components/com_fields/models/groups.php index 93ddb6632d00c..a3f822df48d89 100644 --- a/administrator/components/com_fields/models/groups.php +++ b/administrator/components/com_fields/models/groups.php @@ -8,6 +8,7 @@ */ defined('_JEXEC') or die; +use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; /** @@ -213,4 +214,31 @@ protected function getListQuery() return $query; } + + /** + * Gets an array of objects from the results of database query. + * + * @param string $query The query. + * @param integer $limitstart Offset. + * @param integer $limit The number of records. + * + * @return array An array of results. + * + * @since __DEPLOY_VERSION__ + * @throws RuntimeException + */ + protected function _getList($query, $limitstart = 0, $limit = 0) + { + $result = parent::_getList($query, $limitstart, $limit); + + if (is_array($result)) + { + foreach ($result as $group) + { + $group->params = new Registry($group->params); + } + } + + return $result; + } } diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index b4078de2faa2d..e28bde49cdc7d 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -203,6 +203,8 @@ JFIELD_BASIS_LOGOUT_DESCRIPTION_LABEL="Logout Description Text" JFIELD_BASIS_LOGOUT_DESCRIPTION_SHOW_DESC="Show or hide logout description." JFIELD_BASIS_LOGOUT_DESCRIPTION_SHOW_LABEL="Logout Description" JFIELD_CATEGORY_DESC="The category that this item is assigned to. You may select an existing category or enter a new category by typing the name in the field and pressing enter." +JFIELD_DISPLAY_READONLY_DESC="Select whether to display the field on forms when read-only." +JFIELD_DISPLAY_READONLY_LABEL="Display when read-only" JFIELD_ENABLED_DESC="The enabled status of this item." JFIELD_FIELDS_CATEGORY_DESC="Select the category that this field is assigned to." JFIELD_KEY_REFERENCE_DESC="Used to store information referring to an external resource." From 78b8d0ff234dc4fdcfa473c016a536f833762d57 Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 08:32:31 +0200 Subject: [PATCH 03/10] fix back-end new article --- .../components/com_fields/helpers/fields.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index 5061150df36e6..f9992716aa41e 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -553,17 +553,14 @@ public static function canEditFieldValue($field) */ public static function displayReadOnlyFieldOnForm($field) { - if (!JFactory::getApplication()->isClient('administrator') || !$user->authorise('core.admin')) - { - $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); - $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); - $fieldDisplayReadOnly = $field->params->get('display_readonly', '1'); + $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); + $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); + $fieldDisplayReadOnly = $field->params->get('display_readonly', '1'); - if (($groupDisplayReadOnly == 0 || $fieldDisplayReadOnly == 0) && !FieldsHelper::canEditFieldValue($field)) - { - // Do not display field on form when field is read-only - return false; - } + if (($groupDisplayReadOnly == 0 || $fieldDisplayReadOnly == 0) && !FieldsHelper::canEditFieldValue($field)) + { + // Do not display field on form when field is read-only + return false; } // Display field on form even when field is read-only From f474bee5a2c3ab5e21a1e969abefa6a95e89947f Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 14:28:07 +0200 Subject: [PATCH 04/10] first / seperate check on read-only access --- .../components/com_fields/helpers/fields.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index f9992716aa41e..167662ca0448e 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -553,14 +553,17 @@ public static function canEditFieldValue($field) */ public static function displayReadOnlyFieldOnForm($field) { - $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); - $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); - $fieldDisplayReadOnly = $field->params->get('display_readonly', '1'); - - if (($groupDisplayReadOnly == 0 || $fieldDisplayReadOnly == 0) && !FieldsHelper::canEditFieldValue($field)) + if (!FieldsHelper::canEditFieldValue($field)) { - // Do not display field on form when field is read-only - return false; + $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); + $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); + $fieldDisplayReadOnly = $field->params->get('display_readonly', '1'); + + if (($groupDisplayReadOnly == 0 || $fieldDisplayReadOnly == 0)) + { + // Do not display field on form when field is read-only + return false; + } } // Display field on form even when field is read-only From 2738876c3bda47a3b4c569a23e7a7e1230e27be1 Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 14:36:56 +0200 Subject: [PATCH 05/10] refactor code so show_on parameter is part of helper function --- .../components/com_fields/helpers/fields.php | 16 ++++++++++++++-- .../com_fields/libraries/fieldsplugin.php | 16 ++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index 167662ca0448e..2112586eba560 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -551,8 +551,20 @@ public static function canEditFieldValue($field) * * @since __DEPLOY_VERSION__ */ - public static function displayReadOnlyFieldOnForm($field) + public static function displayFieldOnForm($field) { + $app = JFactory::getApplication(); + + // Detect if the field should be shown at all + if ($field->params->get('show_on') == 1 && $app->isClient('administrator')) + { + return false; + } + elseif ($field->params->get('show_on') == 2 && $app->isClient('site')) + { + return false; + } + if (!FieldsHelper::canEditFieldValue($field)) { $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); @@ -566,7 +578,7 @@ public static function displayReadOnlyFieldOnForm($field) } } - // Display field on form even when field is read-only + // Display field on form return true; } diff --git a/administrator/components/com_fields/libraries/fieldsplugin.php b/administrator/components/com_fields/libraries/fieldsplugin.php index 1d403f331c634..3a88cb0e774e3 100644 --- a/administrator/components/com_fields/libraries/fieldsplugin.php +++ b/administrator/components/com_fields/libraries/fieldsplugin.php @@ -152,20 +152,8 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form return null; } - $app = JFactory::getApplication(); - - // Detect if the field should be shown at all - if ($field->params->get('show_on') == 1 && $app->isClient('administrator')) - { - return; - } - elseif ($field->params->get('show_on') == 2 && $app->isClient('site')) - { - return null; - } - - // Detect if the field is configured to be displayed on the form based on field / group display read-only setting - if (!FieldsHelper::displayReadOnlyFieldOnForm($field)) + // Detect if the field is configured to be displayed on the form + if (!FieldsHelper::displayFieldOnForm($field)) { return null; } From 602cc08d8c03cb299c845f9474767b2d201a9993 Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 15:45:29 +0200 Subject: [PATCH 06/10] implement inherit value in fields + language things --- administrator/components/com_fields/helpers/fields.php | 10 ++++++++-- .../components/com_fields/models/forms/field.xml | 3 ++- administrator/language/en-GB/en-GB.ini | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index 2112586eba560..41787cff698bf 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -569,9 +569,15 @@ public static function displayFieldOnForm($field) { $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); - $fieldDisplayReadOnly = $field->params->get('display_readonly', '1'); + $fieldDisplayReadOnly = $field->params->get('display_readonly', '2'); - if (($groupDisplayReadOnly == 0 || $fieldDisplayReadOnly == 0)) + if ($fieldDisplayReadOnly == '2') + { + // Inherit from field group display read-only setting + $fieldDisplayReadOnly = $groupDisplayReadOnly; + } + + if ($fieldDisplayReadOnly == '0') { // Do not display field on form when field is read-only return false; diff --git a/administrator/components/com_fields/models/forms/field.xml b/administrator/components/com_fields/models/forms/field.xml index 6639c8410d635..59cdaec69e1c0 100644 --- a/administrator/components/com_fields/models/forms/field.xml +++ b/administrator/components/com_fields/models/forms/field.xml @@ -294,10 +294,11 @@ label="JFIELD_DISPLAY_READONLY_LABEL" description="JFIELD_DISPLAY_READONLY_DESC" class="btn-group btn-group-yesno" - default="1" + default="2" > +
diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index e28bde49cdc7d..9eca04c2ef18b 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -203,8 +203,8 @@ JFIELD_BASIS_LOGOUT_DESCRIPTION_LABEL="Logout Description Text" JFIELD_BASIS_LOGOUT_DESCRIPTION_SHOW_DESC="Show or hide logout description." JFIELD_BASIS_LOGOUT_DESCRIPTION_SHOW_LABEL="Logout Description" JFIELD_CATEGORY_DESC="The category that this item is assigned to. You may select an existing category or enter a new category by typing the name in the field and pressing enter." -JFIELD_DISPLAY_READONLY_DESC="Select whether to display the field on forms when read-only." -JFIELD_DISPLAY_READONLY_LABEL="Display when read-only" +JFIELD_DISPLAY_READONLY_DESC="Whether to display the field on forms when read-only. Inherit defaults to value set in field group." +JFIELD_DISPLAY_READONLY_LABEL="Display When Read-Only" JFIELD_ENABLED_DESC="The enabled status of this item." JFIELD_FIELDS_CATEGORY_DESC="Select the category that this field is assigned to." JFIELD_KEY_REFERENCE_DESC="Used to store information referring to an external resource." From b0156d2e69343a317c736c426259ef6523cba0bb Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 15:53:28 +0200 Subject: [PATCH 07/10] loadmodel only when needed --- administrator/components/com_fields/helpers/fields.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index 41787cff698bf..65b9c3f282910 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -567,13 +567,13 @@ public static function displayFieldOnForm($field) if (!FieldsHelper::canEditFieldValue($field)) { - $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); - $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); $fieldDisplayReadOnly = $field->params->get('display_readonly', '2'); if ($fieldDisplayReadOnly == '2') { // Inherit from field group display read-only setting + $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true)); + $groupDisplayReadOnly = $groupModel->getItem($field->group_id)->params->get('display_readonly', '1'); $fieldDisplayReadOnly = $groupDisplayReadOnly; } From 70fb4943b23c59e77ef6dece454e9ee8b2e212d0 Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 16:06:20 +0200 Subject: [PATCH 08/10] changed function comment --- administrator/components/com_fields/helpers/fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index 65b9c3f282910..ef3571e805142 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -543,7 +543,7 @@ public static function canEditFieldValue($field) } /** - * Return a boolean based on field and field group display read-only setting + * Return a boolean based on field (and field group) display / show_on settings * * @param stdClass $field The field * From b983c4ff4cbcca3d71583764750982f540ac5a79 Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 16:13:01 +0200 Subject: [PATCH 09/10] change values order so default value (inherit) is displayed first --- administrator/components/com_fields/models/forms/field.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_fields/models/forms/field.xml b/administrator/components/com_fields/models/forms/field.xml index 59cdaec69e1c0..7958234104aaf 100644 --- a/administrator/components/com_fields/models/forms/field.xml +++ b/administrator/components/com_fields/models/forms/field.xml @@ -296,9 +296,9 @@ class="btn-group btn-group-yesno" default="2" > + - From 41df5e9d1c023b0548d22a42d823c545b6d3cc09 Mon Sep 17 00:00:00 2001 From: ruud68 Date: Wed, 4 Apr 2018 20:36:20 +0200 Subject: [PATCH 10/10] Must use self:: for local static member reference --- administrator/components/com_fields/helpers/fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index ef3571e805142..029ea680b4bed 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -565,7 +565,7 @@ public static function displayFieldOnForm($field) return false; } - if (!FieldsHelper::canEditFieldValue($field)) + if (!self::canEditFieldValue($field)) { $fieldDisplayReadOnly = $field->params->get('display_readonly', '2');