Skip to content

Commit 5610e4e

Browse files
laoneordeutz
authored andcommitted
[com_fields] Change extension variable to context for custom field groups (#13175)
* Change extension variable to context for custom field groups * Stabilizing javascript * Fixing code style error * Check for admin permission of com_fields access correct
1 parent 9e42a87 commit 5610e4e

File tree

27 files changed

+174
-112
lines changed

27 files changed

+174
-112
lines changed

administrator/components/com_admin/sql/updates/mysql/3.7.0-2016-08-29.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CREATE TABLE IF NOT EXISTS `#__fields` (
4141
CREATE TABLE IF NOT EXISTS `#__fields_groups` (
4242
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
4343
`asset_id` int(10) NOT NULL DEFAULT 0,
44-
`extension` varchar(255) NOT NULL DEFAULT '',
44+
`context` varchar(255) NOT NULL DEFAULT '',
4545
`title` varchar(255) NOT NULL DEFAULT '',
4646
`note` varchar(255) NOT NULL DEFAULT '',
4747
`description` text NOT NULL,
@@ -60,7 +60,7 @@ CREATE TABLE IF NOT EXISTS `#__fields_groups` (
6060
KEY `idx_state` (`state`),
6161
KEY `idx_created_by` (`created_by`),
6262
KEY `idx_access` (`access`),
63-
KEY `idx_extension` (`extension`),
63+
KEY `idx_context` (`context`),
6464
KEY `idx_language` (`language`)
6565
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
6666

administrator/components/com_admin/sql/updates/postgresql/3.7.0-2016-08-29.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CREATE INDEX "#__fields_idx_language" ON "#__fields" ("language");
4747
CREATE TABLE "#__fields_groups" (
4848
"id" serial NOT NULL,
4949
"asset_id" bigint DEFAULT 0 NOT NULL,
50-
"extension" varchar(255) DEFAULT '' NOT NULL,
50+
"context" varchar(255) DEFAULT '' NOT NULL,
5151
"title" varchar(255) DEFAULT '' NOT NULL,
5252
"note" varchar(255) DEFAULT '' NOT NULL,
5353
"description" text DEFAULT '' NOT NULL,
@@ -67,7 +67,7 @@ CREATE INDEX "#__fields_idx_checked_out" ON "#__fields_groups" ("checked_out");
6767
CREATE INDEX "#__fields_idx_state" ON "#__fields_groups" ("state");
6868
CREATE INDEX "#__fields_idx_created_by" ON "#__fields_groups" ("created_by");
6969
CREATE INDEX "#__fields_idx_access" ON "#__fields_groups" ("access");
70-
CREATE INDEX "#__fields_idx_extension" ON "#__fields_groups" ("extension");
70+
CREATE INDEX "#__fields_idx_context" ON "#__fields_groups" ("context");
7171
CREATE INDEX "#__fields_idx_language" ON "#__fields_groups" ("language");
7272

7373
--

administrator/components/com_contact/helpers/contact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function addSubmenu($vName)
4848
);
4949
JHtmlSidebar::addEntry(
5050
JText::_('JGLOBAL_FIELD_GROUPS'),
51-
'index.php?option=com_fields&view=groups&extension=com_contact',
51+
'index.php?option=com_fields&view=groups&context=com_contact.contact',
5252
$vName == 'fields.groups'
5353
);
5454
}

administrator/components/com_content/helpers/content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function addSubmenu($vName)
4949
);
5050
JHtmlSidebar::addEntry(
5151
JText::_('JGLOBAL_FIELD_GROUPS'),
52-
'index.php?option=com_fields&view=groups&extension=com_content',
52+
'index.php?option=com_fields&view=groups&context=com_content.article',
5353
$vName == 'fields.groups'
5454
);
5555
}

administrator/components/com_fields/controllers/group.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class FieldsControllerGroup extends JControllerForm
2727
protected $text_prefix = 'COM_FIELDS_GROUP';
2828

2929
/**
30-
* The extension for which the group applies.
30+
* The component for which the group applies.
3131
*
3232
* @var string
3333
* @since __DEPLOY_VERSION__
3434
*/
35-
private $extension;
35+
private $component = '';
3636

3737
/**
3838
* Class constructor.
@@ -45,7 +45,12 @@ public function __construct($config = array())
4545
{
4646
parent::__construct($config);
4747

48-
$this->extension = $this->input->getCmd('extension');
48+
$parts = FieldsHelper::extract($this->input->getCmd('context'));
49+
50+
if ($parts)
51+
{
52+
$this->component = $parts[0];
53+
}
4954
}
5055

5156
/**
@@ -81,7 +86,7 @@ public function batch($model = null)
8186
*/
8287
protected function allowAdd($data = array())
8388
{
84-
return JFactory::getUser()->authorise('core.create', $this->extension);
89+
return JFactory::getUser()->authorise('core.create', $this->component);
8590
}
8691

8792
/**
@@ -100,19 +105,19 @@ protected function allowEdit($data = array(), $key = 'parent_id')
100105
$user = JFactory::getUser();
101106

102107
// Check general edit permission first.
103-
if ($user->authorise('core.edit', $this->extension))
108+
if ($user->authorise('core.edit', $this->component))
104109
{
105110
return true;
106111
}
107112

108113
// Check edit on the record asset (explicit or inherited)
109-
if ($user->authorise('core.edit', $this->extension . '.fieldgroup.' . $recordId))
114+
if ($user->authorise('core.edit', $this->component . '.fieldgroup.' . $recordId))
110115
{
111116
return true;
112117
}
113118

114119
// Check edit own on the record asset (explicit or inherited)
115-
if ($user->authorise('core.edit.own', $this->extension . '.fieldgroup.' . $recordId) || $user->authorise('core.edit.own', $this->extension))
120+
if ($user->authorise('core.edit.own', $this->component . '.fieldgroup.' . $recordId) || $user->authorise('core.edit.own', $this->component))
116121
{
117122
// Existing record already has an owner, get it
118123
$record = $this->getModel()->getItem($recordId);

administrator/components/com_fields/fields.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
/**
33
* @package Joomla.Administrator
44
* @subpackage com_fields
5-
*
5+
*
66
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
77
* @license GNU General Public License version 2 or later; see LICENSE.txt
88
*/
99
defined('_JEXEC') or die;
1010

11+
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
12+
1113
$app = JFactory::getApplication();
12-
$component = $app->getUserStateFromRequest('com_fields.groups.extension', 'extension', '', 'CMD');
14+
$context = $app->getUserStateFromRequest(
15+
'com_fields.groups.context',
16+
'context',
17+
$app->getUserStateFromRequest('com_fields.fields.context', 'context', 'com_content.article', 'CMD'),
18+
'CMD'
19+
);
1320

14-
if (!$component)
15-
{
16-
$parts = explode('.', $app->getUserStateFromRequest('com_fields.fields.context', 'context', '', 'CMD'));
17-
$component = $parts[0];
18-
}
21+
$parts = FieldsHelper::extract($context);
1922

20-
if (!JFactory::getUser()->authorise('core.manage', $component))
23+
if (!$parts || !JFactory::getUser()->authorise('core.manage', $parts[0]))
2124
{
2225
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
2326
}
2427

25-
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
26-
JLoader::register('FieldsHelperInternal', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/internal.php');
27-
2828
$controller = JControllerLegacy::getInstance('Fields');
2929
$controller->execute($app->input->get('task'));
3030
$controller->redirect();

administrator/components/com_fields/helpers/internal.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,24 @@ class FieldsHelperInternal
2121
/**
2222
* Configure the Linkbar.
2323
*
24-
* @param string $component The component the fields are used for
25-
* @param string $vName The view currently active
24+
* @param string $context The context the fields are used for
25+
* @param string $vName The view currently active
2626
*
2727
* @return void
2828
*
2929
* @since __DEPLOY_VERSION__
3030
*/
31-
public static function addSubmenu ($component, $vName)
31+
public static function addSubmenu ($context, $vName)
3232
{
33+
$parts = FieldsHelper::extract($context);
34+
35+
if (!$parts)
36+
{
37+
return;
38+
}
39+
40+
$component = $parts[0];
41+
3342
// Avoid nonsense situation.
3443
if ($component == 'com_fields')
3544
{

administrator/components/com_fields/models/field.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,15 @@ public function getForm($data = array(), $loadData = true)
324324
if (empty($context) && isset($data['context']))
325325
{
326326
$context = $data['context'];
327-
$parts = explode('.', $context);
327+
$parts = FieldsHelper::extract($context);
328328

329329
$this->setState('field.context', $context);
330-
$this->setState('field.component', $parts[0]);
331-
$this->setState('field.section', isset($parts[1]) ? $parts[1] : '');
330+
331+
if ($parts)
332+
{
333+
$this->setState('field.component', $parts[0]);
334+
$this->setState('field.section', $parts[1]);
335+
}
332336
}
333337

334338
// Get the form.
@@ -769,7 +773,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content')
769773
}
770774

771775
$form->setFieldAttribute('type', 'component', $component);
772-
$form->setFieldAttribute('group_id', 'extension', $component);
776+
$form->setFieldAttribute('group_id', 'context', $this->state->get('field.context'));
773777
$form->setFieldAttribute('rules', 'component', $component);
774778

775779
// Trigger the default form events.

administrator/components/com_fields/models/fields.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ protected function populateState($ordering = null, $direction = null)
7878
$this->setState('filter.context', $context);
7979

8080
// Split context into component and optional section
81-
$parts = explode('.', $context);
82-
$this->setState('filter.component', $parts[0]);
83-
$this->setState('filter.section', (count($parts) > 1) ? $parts[1] : null);
81+
$parts = FieldsHelper::extract($context);
82+
83+
if ($parts)
84+
{
85+
$this->setState('filter.component', $parts[0]);
86+
$this->setState('filter.section', $parts[1]);
87+
}
8488
}
8589

8690
/**
@@ -345,7 +349,7 @@ public function getFilterForm($data = array(), $loadData = true)
345349
if ($form)
346350
{
347351
$form->setValue('context', null, $this->getState('filter.context'));
348-
$form->setFieldAttribute('group_id', 'extension', $this->getState('filter.component'), 'filter');
352+
$form->setFieldAttribute('group_id', 'context', $this->getState('filter.context'), 'filter');
349353
}
350354

351355
return $form;
@@ -368,7 +372,7 @@ public function getGroups()
368372
$query->select('title AS text, id AS value, state');
369373
$query->from('#__fields_groups');
370374
$query->where('state IN (0,1)');
371-
$query->where('extension = ' . $db->quote($this->state->get('filter.component')));
375+
$query->where('context = ' . $db->quote($this->state->get('filter.component')));
372376
$query->where('access IN (' . implode(',', $viewlevels) . ')');
373377

374378
$db->setQuery($query);

administrator/components/com_fields/models/fields/fieldgroups.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class JFormFieldFieldgroups extends JFormAbstractlist
2828
*/
2929
protected function getOptions()
3030
{
31-
$extension = (string) $this->element['extension'];
31+
$context = (string) $this->element['context'];
3232
$states = $this->element['state'] ? $this->element['state'] : '0,1';
3333
$states = ArrayHelper::toInteger(explode(',', $states));
3434

@@ -40,7 +40,7 @@ protected function getOptions()
4040
$query->select('title AS text, id AS value, state');
4141
$query->from('#__fields_groups');
4242
$query->where('state IN (' . implode(',', $states) . ')');
43-
$query->where('extension = ' . $db->quote($extension));
43+
$query->where('context = ' . $db->quote($context));
4444
$query->where('access IN (' . implode(',', $viewlevels) . ')');
4545

4646
$db->setQuery($query);

0 commit comments

Comments
 (0)