You are here

public function FieldGroupFormatterPluginManager::getInstance in Field Group 8

Same name and namespace in other branches
  1. 8.3 src/FieldGroupFormatterPluginManager.php \Drupal\field_group\FieldGroupFormatterPluginManager::getInstance()

Overrides PluginManagerBase::getInstance().

Parameters

array $options: An array with the following key/value pairs:

  • format_type: The current format type.
  • group: The current group.
  • prepare: (bool, optional) Whether default values should get merged in the 'configuration' array. Defaults to TRUE.
  • configuration: (array) the configuration for the formatter. The following key value pairs are allowed, and are all optional if 'prepare' is TRUE:

    • label: (string) Position of the label. The default 'field' theme implementation supports the values 'inline', 'above' and 'hidden'. Defaults to 'above'.
    • settings: (array) Settings specific to the formatter. Each setting defaults to the default value specified in the formatter definition.

Return value

\Drupal\field_group\FieldGroupFormatterInterface|null A formatter object or NULL when plugin is not found.

Overrides PluginManagerBase::getInstance

File

src/FieldGroupFormatterPluginManager.php, line 71

Class

FieldGroupFormatterPluginManager
Plugin type manager for all fieldgroup formatters.

Namespace

Drupal\field_group

Code

public function getInstance(array $options) {
  $configuration = $options['configuration'];
  $format_type = $options['format_type'];
  $context = $options['group']->context;

  // Fill in default configuration if needed.
  if (!isset($options['prepare']) || $options['prepare'] == TRUE) {
    $configuration = $this
      ->prepareConfiguration($format_type, $context, $configuration);
  }
  $plugin_id = $format_type;

  // Validate if plugin exists and it's allowed for current context.
  $definition = $this
    ->getDefinition($format_type, FALSE);
  if (!isset($definition['class']) || !in_array($context, $definition['supported_contexts'])) {
    return NULL;
  }
  $configuration += array(
    'group' => $options['group'],
  );
  return $this
    ->createInstance($plugin_id, $configuration);
}