Skip to content

Commit

Permalink
Fixed #11518
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jun 28, 2022
1 parent bfa5517 commit b7f92b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 11 additions & 14 deletions src/base/FieldLayoutComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function conditional(): bool
*/
public function hasConditions(): bool
{
return isset($this->_userCondition) || isset($this->_elementCondition);
return $this->getUserCondition() || $this->getElementCondition();
}

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -238,7 +232,7 @@ public function getSettingsHtml(): string
$html .= '<hr>';
}

$userCondition = $this->_userCondition ?? self::defaultUserCondition();
$userCondition = $this->getUserCondition() ?? self::defaultUserCondition();
$userCondition->mainTag = 'div';
$userCondition->id = 'user-condition';
$userCondition->name = 'userCondition';
Expand All @@ -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';
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit b7f92b6

Please sign in to comment.