function BaseFieldDefinition::setDisplayOptions

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::setDisplayOptions()
  2. 10 core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::setDisplayOptions()
  3. 11.x core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::setDisplayOptions()

Sets the display options for the field in forms or rendered entities.

This enables generic rendering of the field with widgets / formatters, including automated support for "In place editing", and with optional configurability in the "Manage display" / "Manage form display" UI screens.

Unless this method is called, the field remains invisible (or requires ad-hoc rendering logic).

Parameters

string $display_context: The display context. Either 'view' or 'form'.

array $options: An array of display options. Refer to \Drupal\Core\Field\FieldDefinitionInterface::getDisplayOptions() for a list of supported keys. The options should include at least a 'weight', or specify 'region' = 'hidden'. The 'default_widget' / 'default_formatter' for the field type will be used if no 'type' is specified.

Return value

static The object itself for chaining.

File

core/lib/Drupal/Core/Field/BaseFieldDefinition.php, line 381

Class

BaseFieldDefinition
A class for defining entity fields.

Namespace

Drupal\Core\Field

Code

public function setDisplayOptions($display_context, array $options) {
    $this->definition['display'][$display_context]['options'] = $options;
    return $this;
}

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