You are here

public function Formatter::getFormatterType in Custom Formatters 8.3

Return the formatter type plugin.

Return value

FormatterTypeInterface|bool The formatter type plugin or FALSE if no plugin found.

Overrides FormatterInterface::getFormatterType

File

src/Entity/Formatter.php, line 86

Class

Formatter
Defines the formatter entity.

Namespace

Drupal\custom_formatters\Entity

Code

public function getFormatterType() {

  /** @var \Drupal\custom_formatters\FormatterTypeManager $plugin_manager */
  $plugin_manager = \Drupal::service('plugin.manager.custom_formatters.formatter_type');

  // Ensure Formatter Type exists.
  if (!isset($plugin_manager
    ->getDefinitions()[$this
    ->get('type')])) {

    // @TODO - Add better error handling here.
    return FALSE;
  }
  return $plugin_manager
    ->createInstance($this
    ->get('type'), [
    'entity' => $this,
  ]);
}