Programmatically enable the entity view display I would like to programmatically enable the Layout Builder module. I  followed the instructions given on Layout Builder — building Drupal 8 layouts, but they don't seem to work. They might be outdated for Drupal 9.1. Specifically, I'm having a hard time getting the following piece of code to work.
$entityViewDisplay = \Drupal::entityTypeManager-&gt;getStorage('entity_view_display')
  -&gt;load('ENTITY_TYPE.ENTITY_BUNDLE.VIEW_MODE');

Can anyone help me understand it? I just keep getting a NULL result.
I figured it out. You can enable Layout Builder by running the following code in a custom module:
$entity_type = 'node';
$content_type = 'article';
$view_type = 'default';

\Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::load(&quot;{$entity_type}.{$content_type}.{$view_type}&quot;)
  -&gt;enableLayoutBuilder()
  -&gt;setOverridable()
  -&gt;save();

Hopefully this helps someone else. Having to do it via the UI is painful if you have a lot of content types. I'm actually surprised this isn't a Drush command yet. Oh well.
Source: https://www.drupal.org/project/drupal/issues/3158916