FieldStorageAddForm::configureEntityViewDisplay

protected FieldStorageAddForm::configureEntityViewDisplay($field_name, $formatter_id = NULL)

Configures the newly created field for the default view and form modes.

Parameters

string $field_name: The field name.

string|null $formatter_id: (optional) The plugin ID of the formatter. Defaults to NULL.

File

core/modules/field_ui/src/Form/FieldStorageAddForm.php, line 450

Class

FieldStorageAddForm
Provides a form for the "field storage" add page.

Namespace

Drupal\field_ui\Form

Code

protected function configureEntityViewDisplay($field_name, $formatter_id = NULL) {
  // Make sure the field is displayed in the 'default' view mode (using
  // default formatter and settings). It stays hidden for other view
  // modes until it is explicitly configured.
  $options = $formatter_id ? ['type' => $formatter_id] : [];
  entity_get_display($this->entityTypeId, $this->bundle, 'default')
    ->setComponent($field_name, $options)
    ->save();
}
doc_Drupal
2016-10-29 09:12:07
Comments
Leave a Comment

Please login to continue.