function FieldStorageAddForm::configureEntityViewDisplay

Same name in other branches
  1. 8.9.x core/modules/field_ui/src/Form/FieldStorageAddForm.php \Drupal\field_ui\Form\FieldStorageAddForm::configureEntityViewDisplay()

Configures the field for the default view mode.

Parameters

string $field_name: The field name.

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

array $formatter_settings: (optional) An array of formatter settings. Defaults to an empty array.

1 call to FieldStorageAddForm::configureEntityViewDisplay()
FieldStorageAddForm::submitForm in core/modules/field_ui/src/Form/FieldStorageAddForm.php
Form submission handler.

File

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

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, array $formatter_settings = []) {
    $options = [];
    if ($formatter_id) {
        $options['type'] = $formatter_id;
        if (!empty($formatter_settings)) {
            $options['settings'] = $formatter_settings;
        }
    }
    // 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.
    $this->entityDisplayRepository
        ->getViewDisplay($this->entityTypeId, $this->bundle)
        ->setComponent($field_name, $options)
        ->save();
}

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