public function EntityDisplayBase::setComponent

Sets the display options for a component.

Parameters

string $name: The name of the component.

array $options: The display options.

Return value

\Drupal\entity\Plugin\Core\Entity\EntityDisplay The EntityDisplay object.

Overrides EntityDisplayBaseInterface::setComponent

File

drupal/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php, line 215
Contains \Drupal\entity\EntityDisplayBase.

Class

EntityDisplayBase
Base class for config entity types that store configuration for entity forms and displays.

Namespace

Drupal\entity

Code

public function setComponent($name, array $options = array()) {

  // 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;
  }
  if ($instance = field_info_instance($this->targetEntityType, $name, $this->bundle)) {
    $field = field_info_field($instance['field_name']);
    $options = $this->pluginManager
      ->prepareConfiguration($field['type'], $options);

    // Clear the persisted plugin, if any.
    unset($this->plugins[$name]);
  }

  // We always store 'extra fields', whether they are visible or hidden.
  $extra_fields = field_info_extra_fields($this->targetEntityType, $this->bundle, $this->displayContext);
  if (isset($extra_fields[$name])) {
    $options['visible'] = TRUE;
  }
  $this->content[$name] = $options;
  return $this;
}