Skip to content

Commit 5e3762b

Browse files
committed
Fixed #13097
1 parent 7bd8acb commit 5e3762b

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Fixed an error that occured when sending the activation email for a new user, if there were any validation errors due to new group assignments. ([#13060](https://github.com/craftcms/cms/issues/13060))
1414
- Fixed a bug where the “Send an activation email now” user account checkbox was losing its value if there were any validation errors.
1515
- Fixed an error that could occur when creating a database backup on MySQL and MariaDB. ([#12996](https://github.com/craftcms/cms/issues/12996))
16+
- Fixed a bug where Edit Category screens were including a Parent field, even if the category group’s Max Levels was set to `1`. ([#13097](https://github.com/craftcms/cms/discussions/13097))
1617

1718
## 4.4.7.1 - 2023-04-15
1819

src/elements/Category.php

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -641,41 +641,43 @@ protected function metaFieldsHtml(bool $static): string
641641
$this->slugFieldHtml($static),
642642
];
643643

644-
$fields[] = (function() use ($static) {
645-
if ($parentId = $this->getParentId()) {
646-
$parent = Craft::$app->getCategories()->getCategoryById($parentId, $this->siteId, [
647-
'drafts' => null,
648-
'draftOf' => false,
649-
]);
650-
} else {
651-
// If the category already has structure data, use it. Otherwise, use its canonical category
652-
/** @var self|null $parent */
653-
$parent = self::find()
654-
->siteId($this->siteId)
655-
->ancestorOf($this->lft ? $this : ($this->getIsCanonical() ? $this->id : $this->getCanonical(true)))
656-
->ancestorDist(1)
657-
->drafts(null)
658-
->draftOf(false)
659-
->status(null)
660-
->one();
661-
}
644+
$group = $this->getGroup();
662645

663-
$group = $this->getGroup();
646+
if ($group->maxLevels !== 1) {
647+
$fields[] = (function() use ($static, $group) {
648+
if ($parentId = $this->getParentId()) {
649+
$parent = Craft::$app->getCategories()->getCategoryById($parentId, $this->siteId, [
650+
'drafts' => null,
651+
'draftOf' => false,
652+
]);
653+
} else {
654+
// If the category already has structure data, use it. Otherwise, use its canonical category
655+
/** @var self|null $parent */
656+
$parent = self::find()
657+
->siteId($this->siteId)
658+
->ancestorOf($this->lft ? $this : ($this->getIsCanonical() ? $this->id : $this->getCanonical(true)))
659+
->ancestorDist(1)
660+
->drafts(null)
661+
->draftOf(false)
662+
->status(null)
663+
->one();
664+
}
664665

665-
return Cp::elementSelectFieldHtml([
666-
'label' => Craft::t('app', 'Parent'),
667-
'id' => 'parentId',
668-
'name' => 'parentId',
669-
'elementType' => self::class,
670-
'selectionLabel' => Craft::t('app', 'Choose'),
671-
'sources' => ["group:$group->uid"],
672-
'criteria' => $this->_parentOptionCriteria($group),
673-
'limit' => 1,
674-
'elements' => $parent ? [$parent] : [],
675-
'disabled' => $static,
676-
'describedBy' => 'parentId-label',
677-
]);
678-
})();
666+
return Cp::elementSelectFieldHtml([
667+
'label' => Craft::t('app', 'Parent'),
668+
'id' => 'parentId',
669+
'name' => 'parentId',
670+
'elementType' => self::class,
671+
'selectionLabel' => Craft::t('app', 'Choose'),
672+
'sources' => ["group:$group->uid"],
673+
'criteria' => $this->_parentOptionCriteria($group),
674+
'limit' => 1,
675+
'elements' => $parent ? [$parent] : [],
676+
'disabled' => $static,
677+
'describedBy' => 'parentId-label',
678+
]);
679+
})();
680+
}
679681

680682
$fields[] = parent::metaFieldsHtml($static);
681683

0 commit comments

Comments
 (0)