Overrides PluginManagerBase::getInstance().
array $options: An array with the following key/value pairs:
\Drupal\field\Plugin\Type\Formatter\FormatterInterface A formatter object.
Overrides PluginManagerBase::getInstance
public function getInstance(array $options) {
$configuration = $options['configuration'];
$instance = $options['instance'];
$field = field_info_field($instance['field_name']);
// Fill in default configuration if needed.
if (!isset($options['prepare']) || $options['prepare'] == TRUE) {
$configuration = $this
->prepareConfiguration($field['type'], $configuration);
}
$plugin_id = $configuration['type'];
// Switch back to default formatter if either:
// - $type_info doesn't exist (the widget type is unknown),
// - the field type is not allowed for the widget.
$definition = $this
->getDefinition($configuration['type']);
if (!isset($definition['class']) || !in_array($field['type'], $definition['field_types'])) {
// Grab the default widget for the field type.
$field_type_definition = field_info_field_types($field['type']);
$plugin_id = $field_type_definition['default_formatter'];
}
$configuration += array(
'instance' => $instance,
'view_mode' => $options['view_mode'],
);
return $this
->createInstance($plugin_id, $configuration);
}