function entity_get_form_display

Returns the entity_form_display object associated to 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 configuration entry exists yet for this bundle and form mode. This streamlines manipulation of EntityFormDisplay objects 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.
entity_get_form_display('node', 'article', 'default')
  ->setComponent('body', array(
  'type' => 'text_textarea_with_summary',
  'weight' => 1,
))
  ->setComponent('field_image', array(
  'type' => 'hidden',
))
  ->save();

Parameters

string $entity_type: The entity type.

string $bundle: The bundle.

string $form_mode: The form mode.

Return value

\Drupal\entity\Plugin\Core\Entity\EntityFormDisplay The EntityFormDisplay object associated to the form mode.

12 calls to entity_get_form_display()
EntityFormDisplayTest::testEntityGetFromDisplay in drupal/core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php
Tests entity_get_form_display().
entity_get_render_form_display in drupal/core/includes/entity.inc
Returns the entity_form_display object used to render an entity form.
FieldAttachOtherTest::testFieldAttachExtractFormValues in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field_attach_extract_form_values().
FieldAttachOtherTest::testFieldAttachForm in drupal/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
Test field_attach_form().
FieldInstanceEditForm::buildForm in drupal/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
Form constructor.

... See full list

File

drupal/core/includes/entity.inc, line 748
Entity API for handling entities like nodes or users.

Code

function entity_get_form_display($entity_type, $bundle, $form_mode) {

  // Try loading the entity from configuration.
  $entity_form_display = entity_load('entity_form_display', $entity_type . '.' . $bundle . '.' . $form_mode);

  // If not found, create a fresh entity object. We do not preemptively create
  // new EntityFormDisplay configuration entries for each existing entity type
  // and bundle whenever a new form mode becomes available. Instead,
  // configuration entries are only created when a EntityFormDisplay object is
  // explicitly configured and saved.
  if (!$entity_form_display) {
    $entity_form_display = entity_create('entity_form_display', array(
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
      'mode' => $form_mode,
    ));
  }
  return $entity_form_display;
}