We are looking for the best way to export a defined/built layout with inline blocks and then use that to programmatically set both them during a module install.


  • module install
    • create node in content type
    • apply section
    • create and apply block to section in node

Currently we are having to print the array, strip UUIDs.. then attach them to the layout field value of the node we create. Which can lead to issues if not cleaned up correctly.

  • Did you solve this? Can you post an answer?
    – Jason
    Commented May 3, 2020 at 21:10

1 Answer 1


Put this code in an .install file:

// Create a Home web page with alias 'home'.
  $node = Node::create([
    'type' => '<node_type>',
    'langcode' => 'en',
    'uid' => 1,
    'title' => 'Home',
    'status' => 1,
    'path' => [
      'alias' => '/home',
      'pathauto' => PathautoState::SKIP,

  // Variable to hold the sections for this node.
  // Defaulting to have a blank section first.
  $sections[] = new Section('layout_onecol');

  // Create a new section.
  $section = new Section('layout_onecol');

  // Config for the multi-type list block.
  $pluginConfiguration = [
    'id' => '<block_id>',
    'provider' => 'entity_block',
    'label_display' => FALSE,
    'view_mode' => 'default',

  // Create a new section component using the node and plugin config.
  $component = new SectionComponent($node->uuid(), 'content', $pluginConfiguration);

  // Add the component to the section.

  // Add the section to the sections array.
  $sections[] = $section;

  // Set the sections.

  // Save the node.
  • You can't just "put this code inside a .install file" and expect it to work, right? Wouldn't you need to put it inside a hook_install() function?
    – sonfd
    Commented Aug 5, 2020 at 12:25
  • This code will result in: Call to a member function setValue() on null
    – DiDebru
    Commented Mar 2, 2021 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.