You are here

function lightning_media_entity_get_form_display in Lightning Media 8.3

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

This is an exact copy of the deprecated entity_get_form_display() from Core 8.6.x except for one change: the default value of the $form_mode parameter.

@todo Eliminate this in favor of \Drupal::service('entity_display.repository')->getFormDisplay() in Core 8.8.x once that is the lowest supported version.

Parameters

string $entity_type: The entity type.

string $bundle: The bundle.

string $form_mode: The form 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 calls to lightning_media_entity_get_form_display()
lightning_media_image_update_8005 in modules/lightning_media_image/lightning_media_image.install
Removes the file link(s) and Remove button from the media_browser form.
MediaImageFieldTest::test in tests/src/FunctionalJavascript/MediaImageFieldTest.php
Tests clearing an image field on an existing media item.

File

./lightning_media.module, line 647
Core media asset support for Lightning.

Code

function lightning_media_entity_get_form_display($entity_type, $bundle, $form_mode = 'default') {

  // Try loading the entity from configuration.
  $entity_form_display = EntityFormDisplay::load($entity_type . '.' . $bundle . '.' . $form_mode);

  // 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.
  if (!$entity_form_display) {
    $entity_form_display = EntityFormDisplay::create([
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
      'mode' => $form_mode,
      'status' => TRUE,
    ]);
  }
  return $entity_form_display;
}