diff --git a/src/EventSubscriber/LayoutParagraphsRestrictions.php b/src/EventSubscriber/LayoutParagraphsRestrictions.php index 58163ba011bd847ab5cc3e645de92093824e88bc..7fe34fe244fee40bc1c2a7f0e74640e5a4796128 100644 --- a/src/EventSubscriber/LayoutParagraphsRestrictions.php +++ b/src/EventSubscriber/LayoutParagraphsRestrictions.php @@ -98,13 +98,13 @@ class LayoutParagraphsRestrictions implements EventSubscriberInterface { $include = []; $exclude = []; + foreach ($this->restrictions as $restriction) { + $total_tests = 0; + $matched_tests = 0; + foreach ($restriction['context'] as $restriction_context_key => $restriction_context_value) { - if (!is_string($restriction_context_value)) { - $this->loggerFactory->get('layout_paragraphs_restrictions')->error('Invalid Layout Paragraphs Restrictions context: @value', [ - '@value' => print_r($restriction_context_value, TRUE), - ]); - } + $total_tests++; if (str_starts_with($restriction_context_value, '!')) { $restriction_context_value = substr($restriction_context_value, 1); @@ -115,21 +115,28 @@ class LayoutParagraphsRestrictions implements EventSubscriberInterface { $test = isset($context[$restriction_context_key]) && $context[$restriction_context_key] == $restriction_context_value; } + if ($test === TRUE) { - if (!empty($restriction['components'])) { - $include = array_merge($include, array_fill_keys($restriction['components'], TRUE)); - } - if (!empty($restriction['exclude_components'])) { - $exclude = array_merge($exclude, array_fill_keys($restriction['exclude_components'], TRUE)); - } + $matched_tests++; + } + } + + // If all tests matched, apply the restrictions. + if ($matched_tests === $total_tests) { + if (!empty($restriction['components'])) { + $include = array_merge($include, array_fill_keys($restriction['components'], TRUE)); + } + if (!empty($restriction['exclude_components'])) { + $exclude = array_merge($exclude, array_fill_keys($restriction['exclude_components'], TRUE)); + } + + if ($include) { + $event->setTypes(array_intersect_key($event->getTypes(), $include)); + } + if ($exclude) { + $event->setTypes(array_diff_key($event->getTypes(), $exclude)); } } - } - if ($include) { - $event->setTypes(array_intersect_key($event->getTypes(), $include)); - } - if ($exclude) { - $event->setTypes(array_diff_key($event->getTypes(), $exclude)); } }