diff --git a/CHANGELOG.md b/CHANGELOG.md
index a33a0424a2e..16cd0ca8f37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# Release Notes for Craft CMS 4
+## Unreleased
+
+### Fixed
+- Fixed a PHP error. ([#11518](https://github.com/craftcms/cms/issues/11518))
+
## 4.1.0.1 - 2022-06-28
### Fixed
diff --git a/src/base/FieldLayoutComponent.php b/src/base/FieldLayoutComponent.php
index 7ca54f8c893..53c54c1537d 100644
--- a/src/base/FieldLayoutComponent.php
+++ b/src/base/FieldLayoutComponent.php
@@ -126,7 +126,7 @@ protected function conditional(): bool
*/
public function hasConditions(): bool
{
- return isset($this->_userCondition) || isset($this->_elementCondition);
+ return $this->getUserCondition() || $this->getElementCondition();
}
/**
@@ -208,14 +208,8 @@ private function _normalizeCondition(mixed $condition): ?ConditionInterface
public function fields(): array
{
$fields = parent::fields();
-
- if (isset($this->_userCondition)) {
- $fields['userCondition'] = fn() => $this->getUserCondition()->getConfig();
- }
- if (isset($this->_elementCondition)) {
- $fields['elementCondition'] = fn() => $this->getElementCondition()->getConfig();
- }
-
+ $fields['userCondition'] = fn() => $this->getUserCondition()?->getConfig();
+ $fields['elementCondition'] = fn() => $this->getElementCondition()?->getConfig();
return $fields;
}
@@ -238,7 +232,7 @@ public function getSettingsHtml(): string
$html .= '
';
}
- $userCondition = $this->_userCondition ?? self::defaultUserCondition();
+ $userCondition = $this->getUserCondition() ?? self::defaultUserCondition();
$userCondition->mainTag = 'div';
$userCondition->id = 'user-condition';
$userCondition->name = 'userCondition';
@@ -254,7 +248,7 @@ public function getSettingsHtml(): string
$elementType = $this->getLayout()->type;
if ($elementType && is_subclass_of($elementType, ElementInterface::class)) {
- $elementCondition = $this->_elementCondition ?? self::defaultElementCondition($elementType);
+ $elementCondition = $this->getElementCondition() ?? self::defaultElementCondition($elementType);
$elementCondition->mainTag = 'div';
$elementCondition->id = 'element-condition';
$elementCondition->name = 'elementCondition';
@@ -296,14 +290,17 @@ protected function settingsHtml(): ?string
public function showInForm(?ElementInterface $element = null): bool
{
if ($this->conditional()) {
- if (isset($this->_userCondition)) {
+ $userCondition = $this->getUserCondition();
+ $elementCondition = $this->getElementCondition();
+
+ if ($userCondition) {
$currentUser = Craft::$app->getUser()->getIdentity();
- if ($currentUser && !$this->getUserCondition()->matchElement($currentUser)) {
+ if ($currentUser && !$userCondition->matchElement($currentUser)) {
return false;
}
}
- if (isset($this->_elementCondition) && $element && !$this->getElementCondition()->matchElement($element)) {
+ if ($elementCondition && $element && !$elementCondition->matchElement($element)) {
return false;
}
}