-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Fields toggle display on read only rights #20068
Changes from 6 commits
b2c4d4e
8c87352
78b8d0f
f474bee
2738876
602cc08
b0156d2
70fb494
b983c4f
41df5e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -542,6 +542,52 @@ 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 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small performance improvement, load the model in the if below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, in next PR |
||
$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 | ||
$fieldDisplayReadOnly = $groupDisplayReadOnly; | ||
} | ||
|
||
if ($fieldDisplayReadOnly == '0') | ||
{ | ||
// Do not display field on form when field is read-only | ||
return false; | ||
} | ||
} | ||
|
||
// Display field on form | ||
return true; | ||
} | ||
|
||
/** | ||
* Adds Count Items for Category Manager. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit hesitant to approve the pr, because this here is a minor BC break. Are we sure that it breaks nothing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @laoneo , have you tested this? Do you have any scenario's in which this would break? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In core I guess it should be fine. But if an extension is using the params of a group, loaded through the model it has now a different behavior. But this chance is relative small and the pr got merged, so I guess the discussion is superfluous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but there was no params of a group, I created that in this PR. So the only thing that could break is if an extension developer created its own params for a group and 'forgot' to share that back to Joomla. And then it would only break if the implementation is different. If the developer followed joomla guidelines, then it should not break. But then again... maybe I am a bit naive :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I'm talking about is the following code $group->params returns before the pr a string and after a Registry. Which can be counted as a minir BC break. |
||
} | ||
|
||
// Convert the created and modified dates to local user time for display in the form. | ||
$tz = new DateTimeZone(JFactory::getApplication()->get('offset')); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change FieldsHelper::canEditFieldValue to self::canEditFieldValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Thanks Robert :)