Returns the Formatter plugin for a field.
string $field_name: The field name.
\Drupal\field\Plugin\Type\Formatter\FormatterInterface If the field is not hidden, the Formatter plugin to use for rendering it.
Overrides EntityDisplayInterface::getFormatter
public function getFormatter($field_name) {
if (isset($this->plugins[$field_name])) {
return $this->plugins[$field_name];
}
// Instantiate the formatter object from the stored display properties.
if ($configuration = $this
->getComponent($field_name)) {
$instance = field_info_instance($this->targetEntityType, $field_name, $this->bundle);
$formatter = $this->pluginManager
->getInstance(array(
'instance' => $instance,
'view_mode' => $this->originalMode,
// No need to prepare, defaults have been merged in setComponent().
'prepare' => FALSE,
'configuration' => $configuration,
));
}
else {
$formatter = NULL;
}
// Persist the formatter object.
$this->plugins[$field_name] = $formatter;
return $formatter;
}