You are here

public function EntityDisplayRepositoryInterface::getFormDisplay in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getFormDisplay()
  2. 10 core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php \Drupal\Core\Entity\EntityDisplayRepositoryInterface::getFormDisplay()

Returns the entity form display associated with a bundle and form mode.

The function reads the entity form display object from the current configuration, or returns a ready-to-use empty one if no configuration entry exists yet for this bundle and form mode. This streamlines manipulation of entity form displays by always returning a consistent object that reflects the current state of the configuration.

Example usage:

  • Set the 'body' field to be displayed with the 'text_textarea_with_summary' widget and the 'field_image' field to be hidden on article nodes in the 'default' form mode.
\Drupal::service('entity_display.repository')
  ->getFormDisplay('node', 'article', 'default')
  ->setComponent('body', array(
  'type' => 'text_textarea_with_summary',
  'weight' => 1,
))
  ->setComponent('field_image', array(
  'region' => 'hidden',
))
  ->save();

Parameters

string $entity_type: The entity type.

string $bundle: The bundle.

string $form_mode: (optional) The form mode. Defaults to self::DEFAULT_DISPLAY_MODE.

Return value

\Drupal\Core\Entity\Display\EntityFormDisplayInterface The entity form display associated with the given form mode.

See also

\Drupal\Core\Entity\EntityStorageInterface::create()

\Drupal\Core\Entity\EntityStorageInterface::load()

2 methods override EntityDisplayRepositoryInterface::getFormDisplay()
EntityDisplayRepository::getFormDisplay in core/lib/Drupal/Core/Entity/EntityDisplayRepository.php
Returns the entity form display associated with a bundle and form mode.
EntityManager::getFormDisplay in core/lib/Drupal/Core/Entity/EntityManager.php

File

core/lib/Drupal/Core/Entity/EntityDisplayRepositoryInterface.php, line 190

Class

EntityDisplayRepositoryInterface
Provides an interface for an entity display repository.

Namespace

Drupal\Core\Entity

Code

public function getFormDisplay($entity_type, $bundle, $form_mode = self::DEFAULT_DISPLAY_MODE);