Skip to content

Commit 38b38f0

Browse files
authored
Make the current user available in form fields (#40425)
* Make the current user available in form fields * test
1 parent ffa3108 commit 38b38f0

File tree

16 files changed

+41
-20
lines changed

16 files changed

+41
-20
lines changed

administrator/components/com_categories/src/Field/CategoryeditField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected function getOptions()
170170
: (int) $oldCat;
171171

172172
$db = $this->getDatabase();
173-
$user = Factory::getUser();
173+
$user = $this->getCurrentUser();
174174

175175
$query = $db->getQuery(true)
176176
->select(

administrator/components/com_fields/src/Field/FieldgroupsField.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace Joomla\Component\Fields\Administrator\Field;
1212

13-
use Joomla\CMS\Factory;
1413
use Joomla\CMS\Form\Field\ListField;
1514
use Joomla\Utilities\ArrayHelper;
1615

@@ -43,7 +42,7 @@ protected function getOptions()
4342
$states = $this->element['state'] ?: '0,1';
4443
$states = ArrayHelper::toInteger(explode(',', $states));
4544

46-
$user = Factory::getUser();
45+
$user = $this->getCurrentUser();
4746
$viewlevels = ArrayHelper::toInteger($user->getAuthorisedViewLevels());
4847

4948
$db = $this->getDatabase();

administrator/components/com_messages/src/Field/UserMessagesField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ protected function getGroups()
8484
*/
8585
protected function getExcluded()
8686
{
87-
return [Factory::getUser()->id];
87+
return [$this->getCurrentUser()->id];
8888
}
8989
}

administrator/components/com_users/src/Field/GroupparentField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function getOptions()
8181
}
8282

8383
$options = array_values($options);
84-
$isSuperAdmin = Factory::getUser()->authorise('core.admin');
84+
$isSuperAdmin = $this->getCurrentUser()->authorise('core.admin');
8585

8686
// Pad the option text with spaces using depth level as a multiplier.
8787
for ($i = 0, $n = count($options); $i < $n; $i++) {

libraries/src/Form/Field/CategoryField.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Joomla\CMS\Form\Field;
1111

12-
use Joomla\CMS\Factory;
1312
use Joomla\CMS\HTML\HTMLHelper;
1413
use Joomla\CMS\Language\Text;
1514
use Joomla\CMS\Log\Log;
@@ -74,7 +73,7 @@ protected function getOptions()
7473
// Verify permissions. If the action attribute is set, then we scan the options.
7574
if ((string) $this->element['action']) {
7675
// Get the current user object.
77-
$user = Factory::getUser();
76+
$user = $this->getCurrentUser();
7877

7978
foreach ($options as $i => $option) {
8079
/*

libraries/src/Form/Field/FrontendlanguageField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function getOptions()
6464
} catch (\RuntimeException $e) {
6565
$languages = [];
6666

67-
if (Factory::getUser()->authorise('core.admin')) {
67+
if ($this->getCurrentUser()->authorise('core.admin')) {
6868
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
6969
}
7070
}

libraries/src/Form/Field/MenuField.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Joomla\CMS\Form\Field;
1111

12-
use Joomla\CMS\Factory;
1312
use Joomla\CMS\Language\Text;
1413
use Joomla\Database\ParameterType;
1514

@@ -73,7 +72,7 @@ protected function getGroups()
7372
$menus = $db->setQuery($query)->loadObjectList();
7473

7574
if ($accessType) {
76-
$user = Factory::getUser();
75+
$user = $this->getCurrentUser();
7776

7877
foreach ($menus as $key => $menu) {
7978
switch ($accessType) {

libraries/src/Form/Field/PluginsField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function getOptions()
148148
);
149149

150150
if ((string) $this->element['useaccess'] === 'true') {
151-
$query->whereIn($db->quoteName('access'), Factory::getUser()->getAuthorisedViewLevels());
151+
$query->whereIn($db->quoteName('access'), $this->getCurrentUser()->getAuthorisedViewLevels());
152152
}
153153

154154
$options = $db->setQuery($query)->loadObjectList();

libraries/src/Form/Field/TagField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function allowCustom()
315315
return false;
316316
}
317317

318-
return Factory::getUser()->authorise('core.create', 'com_tags');
318+
return $this->getCurrentUser()->authorise('core.create', 'com_tags');
319319
}
320320

321321
/**

libraries/src/Form/Field/TransitionField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected function getGroups()
135135
$component = reset($parts);
136136

137137
if (\count($items)) {
138-
$user = Factory::getUser();
138+
$user = $this->getCurrentUser();
139139

140140
$items = array_filter(
141141
$items,

0 commit comments

Comments
 (0)