addFormBlock example

// Save the entity view display so that it can be reverted to later.     /** @var \Drupal\Core\Config\StorageInterface $active_config_storage */
    $active_config_storage = $this->container->get('config.storage');
    $original_display_config_data = $active_config_storage->read('core.entity_view_display.node.bundle_with_section_field.default');
    /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_view_display_storage */
    $entity_view_display_storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display');
    $entity_view_display = $entity_view_display_storage->load('node.bundle_with_section_field.default');

    $expected_save_message = 'The layout has been saved.';
    foreach (static::FORM_BLOCK_LABELS as $label) {
      $this->addFormBlock($label, "$field_ui_prefix/display/default", $expected_save_message);
      // Revert the entity view display back to remove the previously added form       // block.       $entity_view_display = $entity_view_display_storage
        ->updateFromStorageRecord($entity_view_display$original_display_config_data);
      $entity_view_display->save();
    }
  }

  /** * Tests blocks containing forms can be successfully saved editing overrides. */
  
Home | Imprint | This part of the site doesn't use cookies.