class LayoutParagraphsAllowedTypesSubscriber in Layout Paragraphs 2.0.x
Hierarchy
- class \Drupal\layout_paragraphs\EventSubscriber\LayoutParagraphsAllowedTypesSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of LayoutParagraphsAllowedTypesSubscriber
1 string reference to 'LayoutParagraphsAllowedTypesSubscriber'
1 service uses LayoutParagraphsAllowedTypesSubscriber
File
- src/
EventSubscriber/ LayoutParagraphsAllowedTypesSubscriber.php, line 8
Namespace
Drupal\layout_paragraphs\EventSubscriberView source
class LayoutParagraphsAllowedTypesSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
LayoutParagraphsAllowedTypesEvent::EVENT_NAME => 'typeRestrictions',
];
}
/**
* Restricts available types based on settings in layout.
*
* @param \Drupal\layout_paragraphs\Event\LayoutParagraphsAllowedTypesEvent $event
* The allowed types event.
*
* @return bool
*/
public function typeRestrictions(LayoutParagraphsAllowedTypesEvent $event) {
$parent_uuid = $event
->getParentUuid();
$types = $event
->getTypes();
$layout = $event
->getLayout();
$settings = $layout
->getSettings();
if ($settings['require_layouts'] && !$parent_uuid) {
$event
->setTypes(array_filter($types, function ($type) {
return $type['is_section'] === TRUE;
}));
}
$depth = 0;
while ($parent = $layout
->getComponentByUuid($parent_uuid)) {
$depth++;
$parent_uuid = $parent
->getParentUuid();
}
if ($depth > $settings['nesting_depth']) {
$event
->setTypes(array_filter($types, function ($type) {
return $type['is_section'] === FALSE;
}));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LayoutParagraphsAllowedTypesSubscriber:: |
public static | function | ||
LayoutParagraphsAllowedTypesSubscriber:: |
public | function | Restricts available types based on settings in layout. |