You are here

public function EntityFormDisplay::getRenderer in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 137
Contains \Drupal\Core\Entity\Entity\EntityFormDisplay.

Class

EntityFormDisplay
Configuration entity that contains widget options for all components of a 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(array(
      '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;
}