Returns the Widget plugin for a field.
string $field_name: The field name.
\Drupal\field\Plugin\Type\Widget\WidgetInterface|null A Widget plugin or NULL if the field does not exist.
Overrides EntityFormDisplayInterface::getWidget
public function getWidget($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)) {
$instance = field_info_instance($this->targetEntityType, $field_name, $this->bundle);
$widget = $this->pluginManager
->getInstance(array(
'instance' => $instance,
'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;
}