You are here

public function SlickFormatterPlugin::getFormatter in Slick Carousel 7.3

Return the requested formatter based on the field type.

Overrides FormatterPlugin::getFormatter

File

src/Plugin/Field/FieldFormatter/SlickFormatterPlugin.php, line 69

Class

SlickFormatterPlugin
Slick formatter initializer.

Namespace

Drupal\slick\Plugin\Field\FieldFormatter

Code

public function getFormatter($type, $field, $instance, $namespace = 'slick') {
  if (!isset($this->formatterType[$type])) {
    $this->formatterType[$type] = FALSE;
    if ($formatter = $this
      ->getActiveFormatter($type, $field, $instance, $namespace)) {
      $this->formatterType[$type] = $formatter;
    }
    elseif ($this->manager
      ->config('deprecated_formatter', TRUE)) {
      foreach (SlickDefault::FIELDS as $entity_type) {
        if ($type == $entity_type) {
          $plugin_id = $namespace . '_' . $type;
          $class = $entity_type == 'field_collection' ? 'FieldCollection' : ucwords($entity_type);
          $class = 'Drupal\\slick\\Plugin\\Field\\FieldFormatter\\Slick' . $class . 'Formatter';
          $this->formatterType[$type] = new $class($plugin_id, $field, $instance, $this->formatter, $this->manager);
          break;
        }
      }
    }
  }
  return $this->formatterType[$type];
}