function EntityDisplayRepository::getFormDisplay

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getFormDisplay()
  2. 10 core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getFormDisplay()
  3. 11.x core/lib/Drupal/Core/Entity/EntityDisplayRepository.php \Drupal\Core\Entity\EntityDisplayRepository::getFormDisplay()

Overrides EntityDisplayRepositoryInterface::getFormDisplay

File

core/lib/Drupal/Core/Entity/EntityDisplayRepository.php, line 272

Class

EntityDisplayRepository
Provides a repository for entity display objects (view modes and form modes).

Namespace

Drupal\Core\Entity

Code

public function getFormDisplay($entity_type, $bundle, $form_mode = self::DEFAULT_DISPLAY_MODE) {
    $storage = $this->entityTypeManager
        ->getStorage('entity_form_display');
    // Try loading the entity from configuration; if not found, create a fresh
    // entity object. We do not preemptively create new entity form display
    // configuration entries for each existing entity type and bundle whenever a
    // new form mode becomes available. Instead, configuration entries are only
    // created when an entity form display is explicitly configured and saved.
    $entity_form_display = $storage->load($entity_type . '.' . $bundle . '.' . $form_mode);
    if (!$entity_form_display) {
        $entity_form_display = $storage->create([
            'targetEntityType' => $entity_type,
            'bundle' => $bundle,
            'mode' => $form_mode,
            'status' => TRUE,
        ]);
    }
    return $entity_form_display;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.