You are here

public function FormatterPluginManager::prepareConfiguration in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/FormatterPluginManager.php \Drupal\Core\Field\FormatterPluginManager::prepareConfiguration()

Merges default values for formatter configuration.

Parameters

string $field_type: The field type.

array $properties: An array of formatter configuration.

Return value

array The display properties with defaults added.

1 call to FormatterPluginManager::prepareConfiguration()
FormatterPluginManager::getInstance in core/lib/Drupal/Core/Field/FormatterPluginManager.php
Overrides PluginManagerBase::getInstance().

File

core/lib/Drupal/Core/Field/FormatterPluginManager.php, line 145
Contains \Drupal\Core\Field\FormatterPluginManager.

Class

FormatterPluginManager
Plugin type manager for field formatters.

Namespace

Drupal\Core\Field

Code

public function prepareConfiguration($field_type, array $configuration) {

  // Fill in defaults for missing properties.
  $configuration += array(
    'label' => 'above',
    'settings' => array(),
    'third_party_settings' => array(),
  );

  // If no formatter is specified, use the default formatter.
  if (!isset($configuration['type'])) {
    $field_type = $this->fieldTypeManager
      ->getDefinition($field_type);
    $configuration['type'] = $field_type['default_formatter'];
  }

  // Filter out unknown settings, and fill in defaults for missing settings.
  $default_settings = $this
    ->getDefaultSettings($configuration['type']);
  $configuration['settings'] = array_intersect_key($configuration['settings'], $default_settings) + $default_settings;
  return $configuration;
}