Skip to content

Commit e3be9d2

Browse files
authored
[5.3] Clean up CategoryEdit form field (joomla#45116)
1 parent 24e4ae3 commit e3be9d2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ protected function getOptions()
152152
// Let's get the id for the current item, either category or content item.
153153
$jinput = Factory::getApplication()->getInput();
154154

155+
// Is this field used to select parent category for a category ?
156+
$isParentCategoryField = isset($this->element['parent']) || $jinput->getCmd('option') === 'com_categories';
157+
155158
// Load the category options for a given extension.
156159

157160
// For categories the old category is the category id or 0 for new category.
158-
if ($this->element['parent'] || $jinput->get('option') == 'com_categories') {
161+
if ($isParentCategoryField) {
159162
$oldCat = $jinput->get('id', 0);
160163
$oldParent = $this->form->getValue($name, 0);
161164
$extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $jinput->get('extension', 'com_content');
@@ -186,7 +189,7 @@ protected function getOptions()
186189
->from($db->quoteName('#__categories', 'a'));
187190

188191
// Filter by the extension type
189-
if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') {
192+
if ($isParentCategoryField) {
190193
$query->where('(' . $db->quoteName('a.extension') . ' = :extension OR ' . $db->quoteName('a.parent_id') . ' = 0)')
191194
->bind(':extension', $extension);
192195
} else {
@@ -195,7 +198,7 @@ protected function getOptions()
195198
}
196199

197200
// Filter language
198-
if (!empty($this->element['language'])) {
201+
if (isset($this->element['language'])) {
199202
if (str_contains($this->element['language'], ',')) {
200203
$language = explode(',', $this->element['language']);
201204
} else {
@@ -219,7 +222,7 @@ protected function getOptions()
219222
$query->order($db->quoteName('a.lft') . ' ASC');
220223

221224
// If parent isn't explicitly stated but we are in com_categories assume we want parents
222-
if ($oldCat != 0 && ($this->element['parent'] == true || $jinput->get('option') == 'com_categories')) {
225+
if ($oldCat != 0 && $isParentCategoryField) {
223226
// Prevent parenting to children of this item.
224227
// To rearrange parents and children move the children up, not the parents down.
225228
$query->join(
@@ -244,10 +247,8 @@ protected function getOptions()
244247
// Pad the option text with spaces using depth level as a multiplier.
245248
foreach ($options as $option) {
246249
// Translate ROOT
247-
if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') {
248-
if ($option->level == 0) {
249-
$option->text = Text::_('JGLOBAL_ROOT_PARENT');
250-
}
250+
if ($isParentCategoryField && $option->level == 0) {
251+
$option->text = Text::_('JGLOBAL_ROOT_PARENT');
251252
}
252253

253254
if ($option->published == 1) {
@@ -311,7 +312,7 @@ protected function getOptions()
311312
}
312313

313314
if (
314-
$oldCat != 0 && ($this->element['parent'] == true || $jinput->get('option') == 'com_categories')
315+
$oldCat != 0 && $isParentCategoryField
315316
&& !isset($options[0])
316317
&& isset($this->element['show_root'])
317318
) {

0 commit comments

Comments
 (0)