You are here

public function EntityFormDisplay::getRenderer in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::getRenderer()
  2. 9 core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php \Drupal\Core\Entity\Entity\EntityFormDisplay::getRenderer()

Gets the renderer plugin for a field (e.g. widget, formatter).

Parameters

string $field_name: The field name.

Return value

\Drupal\Core\Field\PluginSettingsInterface|null A widget or formatter plugin or NULL if the field does not exist.

Overrides EntityDisplayInterface::getRenderer

3 calls to EntityFormDisplay::getRenderer()
EntityFormDisplay::buildForm in core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
Adds field widgets to an entity form.
EntityFormDisplay::extractFormValues in core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
Extracts field values from the submitted widget values into the entity.
EntityFormDisplay::flagWidgetsErrorsFromViolations in core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
Flags entity validation violations as form errors.

File

core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php, line 145

Class

EntityFormDisplay
Configuration entity that contains widget options for all components of an entity form in a given form mode.

Namespace

Drupal\Core\Entity\Entity

Code

public function getRenderer($field_name) {
  if (isset($this->plugins[$field_name])) {
    return $this->plugins[$field_name];
  }

  // Instantiate the widget object from the stored display properties.
  if (($configuration = $this
    ->getComponent($field_name)) && isset($configuration['type']) && ($definition = $this
    ->getFieldDefinition($field_name))) {
    $widget = $this->pluginManager
      ->getInstance([
      'field_definition' => $definition,
      'form_mode' => $this->originalMode,
      // No need to prepare, defaults have been merged in setComponent().
      'prepare' => FALSE,
      'configuration' => $configuration,
    ]);
  }
  else {
    $widget = NULL;
  }

  // Persist the widget object.
  $this->plugins[$field_name] = $widget;
  return $widget;
}