diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php
index 52c9c46c19136..1fd3dd7212934 100644
--- a/administrator/components/com_fields/helpers/fields.php
+++ b/administrator/components/com_fields/helpers/fields.php
@@ -542,6 +542,44 @@ public static function canEditFieldValue($field)
return JFactory::getUser()->authorise('core.edit.value', $parts[0] . '.field.' . (int) $field->id);
}
+ /**
+ * Return a boolean if the actual logged in user is authorised to display the given field on a form.
+ *
+ * @param stdClass $field The field
+ *
+ * @return boolean
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public static function canDisplayFieldOnForm($field)
+ {
+ $user = JFactory::getUser();
+
+ if (!JFactory::getApplication()->isClient('administrator') || !$user->authorise('core.admin'))
+ {
+ $groupModel = JModelLegacy::getInstance('Group', 'FieldsModel', array('ignore_request' => true));
+ $groupDisplayLevel = (array) $groupModel->getItem($field->group_id)->params->get('display_on_form', '1');
+ $fieldDisplayLevel = (array) $field->params->get('display_on_form', '1');
+
+ if ((count($groupDisplayLevel) == 1 && $groupDisplayLevel[0] == '1') && (count($fieldDisplayLevel) == 1 && $fieldDisplayLevel[0] == '1'))
+ {
+ // No user groups configured (default = public) or user groups configured as public
+ return true;
+ }
+
+ $checkGroupDisplayLevel = count(array_intersect($groupDisplayLevel, $user->groups));
+ $checkFieldDisplayLevel = count(array_intersect($fieldDisplayLevel, $user->groups));
+
+ if ($checkGroupDisplayLevel == 0 && $checkFieldDisplayLevel == 0)
+ {
+ // User not in configured user groups for field group or field
+ return false;
+ }
+ }
+
+ 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..50d7df2097d02 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 current user has rights to display field on form
+ if (!FieldsHelper::canDisplayFieldOnForm($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..d9da6780cbe37 100644
--- a/administrator/components/com_fields/models/forms/field.xml
+++ b/administrator/components/com_fields/models/forms/field.xml
@@ -287,6 +287,15 @@
+
+
diff --git a/administrator/components/com_fields/models/forms/group.xml b/administrator/components/com_fields/models/forms/group.xml
index 03a6619019378..565944723b357 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..0523da1948969 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_ON_FORM_DESC="The user group(s) that is allowed to display this item on forms."
+JFIELD_DISPLAY_ON_FORM_LABEL="Display on Forms"
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."