function EntityDisplayBase::setComponent

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayBase.php \Drupal\Core\Entity\EntityDisplayBase::setComponent()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityDisplayBase.php \Drupal\Core\Entity\EntityDisplayBase::setComponent()
  3. 10 core/lib/Drupal/Core/Entity/EntityDisplayBase.php \Drupal\Core\Entity\EntityDisplayBase::setComponent()

Overrides EntityDisplayInterface::setComponent

3 calls to EntityDisplayBase::setComponent()
EntityDisplayBase::init in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
Initializes the display.
EntityDisplayBase::onDependencyRemoval in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
Informs the entity that entities it depends on will be deleted.
LayoutBuilderEntityViewDisplay::setComponent in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Sets the display options for a component.
1 method overrides EntityDisplayBase::setComponent()
LayoutBuilderEntityViewDisplay::setComponent in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Sets the display options for a component.

File

core/lib/Drupal/Core/Entity/EntityDisplayBase.php, line 350

Class

EntityDisplayBase
Provides a common base class for entity view and form displays.

Namespace

Drupal\Core\Entity

Code

public function setComponent($name, array $options = []) {
    // If no weight specified, make sure the field sinks at the bottom.
    if (!isset($options['weight'])) {
        $max = $this->getHighestWeight();
        $options['weight'] = isset($max) ? $max + 1 : 0;
    }
    // For a field, fill in default options.
    if ($field_definition = $this->getFieldDefinition($name)) {
        $options = $this->pluginManager
            ->prepareConfiguration($field_definition->getType(), $options);
    }
    // Ensure we always have an empty settings and array.
    $options += [
        'settings' => [],
        'third_party_settings' => [],
    ];
    $this->content[$name] = $options;
    unset($this->hidden[$name]);
    unset($this->plugins[$name]);
    return $this;
}

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