class FormatterPluginManager

Plugin type manager for field formatters.

Hierarchy

Expanded class hierarchy of FormatterPluginManager

File

drupal/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php, line 20
Definition of Drupal\field\Plugin\Type\Formatter\FormatterPluginManager..

Namespace

Drupal\field\Plugin\Type\Formatter
View source
class FormatterPluginManager extends PluginManagerBase {

  /**
   * Overrides Drupal\Component\Plugin\PluginManagerBase:$defaults.
   */
  protected $defaults = array(
    'field_types' => array(),
    'settings' => array(),
  );

  /**
   * Constructs a FormatterPluginManager object.
   */
  public function __construct() {
    $this->discovery = new AnnotatedClassDiscovery('field', 'formatter');
    $this->discovery = new FormatterLegacyDiscoveryDecorator($this->discovery);
    $this->discovery = new ProcessDecorator($this->discovery, array(
      $this,
      'processDefinition',
    ));
    $this->discovery = new AlterDecorator($this->discovery, 'field_formatter_info');
    $this->discovery = new CacheDecorator($this->discovery, 'field_formatter_types', 'field');
    $this->factory = new FormatterFactory($this);
  }

  /**
   * Overrides PluginManagerBase::getInstance().
   */
  public function getInstance(array $options) {
    $instance = $options['instance'];
    $type = $options['type'];
    $definition = $this
      ->getDefinition($type);
    $field = field_info_field($instance['field_name']);

    // 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.
    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']);
      $type = $field_type_definition['default_formatter'];
    }
    $configuration = array(
      'instance' => $instance,
      'settings' => $options['settings'],
      'weight' => $options['weight'],
      'label' => $options['label'],
      'view_mode' => $options['view_mode'],
    );
    return $this
      ->createInstance($type, $configuration);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormatterPluginManager::$defaults protected property Overrides Drupal\Component\Plugin\PluginManagerBase:$defaults. Overrides PluginManagerBase::$defaults
FormatterPluginManager::getInstance public function Overrides PluginManagerBase::getInstance(). Overrides PluginManagerBase::getInstance
FormatterPluginManager::__construct public function Constructs a FormatterPluginManager object.
PluginManagerBase::$discovery protected property The object that discovers plugins managed by this manager.
PluginManagerBase::$factory protected property The object that instantiates plugins managed by this manager.
PluginManagerBase::$mapper protected property The object that returns the preconfigured plugin instance appropriate for a particular runtime condition.
PluginManagerBase::clearCachedDefinitions public function Implements \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface::clearCachedDefinitions(). Overrides CachedDiscoveryInterface::clearCachedDefinitions
PluginManagerBase::createInstance public function Implements Drupal\Component\Plugin\PluginManagerInterface::createInstance(). Overrides FactoryInterface::createInstance 1
PluginManagerBase::getDefinition public function Implements Drupal\Component\Plugin\PluginManagerInterface::getDefinition(). Overrides DiscoveryInterface::getDefinition 1
PluginManagerBase::getDefinitions public function Implements Drupal\Component\Plugin\PluginManagerInterface::getDefinitions(). Overrides DiscoveryInterface::getDefinitions 1
PluginManagerBase::processDefinition public function Performs extra processing on plugin definitions. 2