Disable layouts programmatically

Drupal provides some layouts by default.

Layout Builder
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/layout_builder/layout_builder.layouts.yml?ref_type=heads

Layout Discovery
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/layout_discovery/layout_discovery.layouts.yml?ref_type=heads

The Layout Disable module can configure layouts to block.

See how that works with hook_layout_alter().

https://git.drupalcode.org/project/layout_disable/-/blob/2.x/layout_disable.module?ref_type=heads#L13

Layout Disable is unable to remove the One column layout, which is required by core for some reason.

See this patch for an example of disabling it in the UI with hook_plugin_filter_TYPE__CONSUMER_alter().

https://www.drupal.org/files/issues/2022-08-31/3307055.patch

Some discussion on the method in this issue.

https://www.drupal.org/project/layout_disable/issues/3398261

Tags