diff --git a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php index 96a16d0..0be215e 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php @@ -55,7 +55,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac } /** - * Returns the default settings of a field widget. + * Returns the default field-level settings for a field type. * * @param string $type * A field type name. @@ -70,10 +70,10 @@ public function getDefaultSettings($type) { } /** - * Returns the default settings of a field widget. + * Returns the default instance-level settings for a field type. * * @param string $type - * A field instance name. + * A field type name. * * @return array * The instance's default settings, as provided by the plugin diff --git a/core/modules/edit/edit.services.yml b/core/modules/edit/edit.services.yml index eb8677e..646878e 100644 --- a/core/modules/edit/edit.services.yml +++ b/core/modules/edit/edit.services.yml @@ -12,7 +12,7 @@ services: - { name: access_check } edit.editor.selector: class: Drupal\edit\EditorSelector - arguments: ['@plugin.manager.edit.editor'] + arguments: ['@plugin.manager.edit.editor', '@plugin.manager.field.formatter'] edit.metadata.generator: class: Drupal\edit\MetadataGenerator arguments: ['@access_check.edit.entity_field', '@edit.editor.selector', '@plugin.manager.edit.editor'] diff --git a/core/modules/edit/lib/Drupal/edit/EditorSelector.php b/core/modules/edit/lib/Drupal/edit/EditorSelector.php index ba75462..f810ab9 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorSelector.php +++ b/core/modules/edit/lib/Drupal/edit/EditorSelector.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\Field\FieldDefinitionInterface; +use Drupal\field\Plugin\Type\Formatter\FormatterPluginManager; /** * Selects an in-place editor (an Editor plugin) for a field. @@ -24,6 +25,13 @@ class EditorSelector implements EditorSelectorInterface { protected $editorManager; /** + * The manager for formatter plugins. + * + * @var \Drupal\field\Plugin\Type\Formatter\FormatterPluginManager. + */ + protected $formatterManager; + + /** * A list of alternative editor plugin IDs, keyed by editor plugin ID. * * @var array @@ -35,9 +43,12 @@ class EditorSelector implements EditorSelectorInterface { * * @param \Drupal\Component\Plugin\PluginManagerInterface * The manager for editor plugins. + * @param \Drupal\field\Plugin\Type\Formatter\FormatterPluginManager + * The formatter manager. */ - public function __construct(PluginManagerInterface $editor_manager) { + public function __construct(PluginManagerInterface $editor_manager, FormatterPluginManager $formatter_manager) { $this->editorManager = $editor_manager; + $this->formatterManager = $formatter_manager; } /** @@ -62,7 +73,7 @@ public function getEditor($formatter_type, FieldDefinitionInterface $field_defin // 'direct' editor. If the formatter doesn't specify, fall back to the // 'form' editor, since that can work for any field. Formatter definitions // can use 'disabled' to explicitly opt out of in-place editing. - $formatter_info = \Drupal::service('plugin.manager.field.formatter')->getDefinition($formatter_type); + $formatter_info = $this->formatterManager->getDefinition($formatter_type); $editor_id = $formatter_info['edit']['editor']; if ($editor_id === 'disabled') { return; diff --git a/core/modules/field/field.services.yml b/core/modules/field/field.services.yml index 6b8c4b8..c6ef5da 100644 --- a/core/modules/field/field.services.yml +++ b/core/modules/field/field.services.yml @@ -1,13 +1,13 @@ services: plugin.manager.field.widget: class: Drupal\field\Plugin\Type\Widget\WidgetPluginManager - arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager'] + arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager', '@plugin.manager.entity.field.field_type'] plugin.manager.field.formatter: class: Drupal\field\Plugin\Type\Formatter\FormatterPluginManager - arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager'] + arguments: ['@container.namespaces', '@cache.field', '@module_handler', '@language_manager', '@plugin.manager.entity.field.field_type'] field.info: class: Drupal\field\FieldInfo - arguments: ['@cache.field', '@config.factory', '@module_handler'] + arguments: ['@cache.field', '@config.factory', '@module_handler', '@plugin.manager.entity.field.field_type'] cache.field: class: Drupal\Core\Cache\CacheBackendInterface tags: diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index bba6678..223b1b7 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\Core\Extension\ModuleHandlerInterface; /** @@ -45,6 +46,13 @@ class FieldInfo { protected $moduleHandler; /** + * The field type manager to define field. + * + * @var \Drupal\Core\Entity\Field\FieldTypePluginManager + */ + protected $fieldTypeManager; + + /** * The config factory. * * @var \Drupal\Core\Config\ConfigFactory @@ -123,11 +131,14 @@ class FieldInfo { * The configuration factory object to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler class to use for invoking hooks. + * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_manager + * The field type manager. */ - public function __construct(CacheBackendInterface $cache_backend, ConfigFactory $config, ModuleHandlerInterface $module_handler) { + public function __construct(CacheBackendInterface $cache_backend, ConfigFactory $config, ModuleHandlerInterface $module_handler, FieldTypePluginManager $field_type_manager) { $this->cacheBackend = $cache_backend; $this->moduleHandler = $module_handler; $this->config = $config; + $this->fieldTypeManager = $field_type_manager; } /** @@ -553,7 +564,7 @@ public function getBundleExtraFields($entity_type, $bundle) { */ public function prepareField($field) { // Make sure all expected field settings are present. - $field['settings'] += \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings($field['type']); + $field['settings'] += $this->fieldTypeManager->getDefaultSettings($field['type']); $field['storage']['settings'] += field_info_storage_settings($field['storage']['type']); return $field; @@ -572,7 +583,7 @@ public function prepareField($field) { */ public function prepareInstance($instance, $field_type) { // Make sure all expected instance settings are present. - $instance['settings'] += \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultInstanceSettings($field_type); + $instance['settings'] += $this->fieldTypeManager->getDefaultInstanceSettings($field_type); // Set a default value for the instance. if (field_behaviors_widget('default value', $instance) == FIELD_BEHAVIOR_DEFAULT && !isset($instance['default_value'])) { diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index d0db597..0cd9d6f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; @@ -31,6 +32,13 @@ class FormatterPluginManager extends DefaultPluginManager { protected $formatterOptions; /** + * The field type manager to define field. + * + * @var \Drupal\Core\Entity\Field\FieldTypePluginManager + */ + protected $fieldTypeManager; + + /** * Constructs a FormatterPluginManager object. * * @param \Traversable $namespaces @@ -42,14 +50,17 @@ class FormatterPluginManager extends DefaultPluginManager { * The module handler. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. + * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_manager + * The field type manager. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManager $field_type_manager) { $annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); parent::__construct('Plugin/field/formatter', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldFormatter'); $this->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types'); $this->alterInfo($module_handler, 'field_formatter_info'); + $this->fieldTypeManager = $field_type_manager; } /** @@ -112,7 +123,7 @@ public function getInstance(array $options) { $definition = $this->getDefinition($configuration['type']); if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) { // Grab the default widget for the field type. - $field_type_definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_type); + $field_type_definition = $this->fieldTypeManager->getDefinition($field_type); $plugin_id = $field_type_definition['default_formatter']; } @@ -142,7 +153,7 @@ public function prepareConfiguration($field_type, array $configuration) { ); // If no formatter is specified, use the default formatter. if (!isset($configuration['type'])) { - $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_type); + $field_type = $this->fieldTypeManager->getDefinition($field_type); $configuration['type'] = $field_type['default_formatter']; } // Fill in default settings values for the formatter. @@ -163,7 +174,7 @@ public function prepareConfiguration($field_type, array $configuration) { */ public function getOptions($field_type = NULL) { if (!isset($this->formatterOptions)) { - $field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions(); + $field_types = $this->fieldTypeManager->getDefinitions(); $options = array(); foreach ($this->getDefinitions() as $name => $formatter) { foreach ($formatter['field_types'] as $formatter_field_type) { diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index 588cc67..dd94c99 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -11,6 +11,7 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\Discovery\ProcessDecorator; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; @@ -24,6 +25,13 @@ class WidgetPluginManager extends DefaultPluginManager { /** + * The field type manager to define field. + * + * @var \Drupal\Core\Entity\Field\FieldTypePluginManager + */ + protected $fieldTypeManager; + + /** * An array of widget options for each field type. * * @var array @@ -42,8 +50,10 @@ class WidgetPluginManager extends DefaultPluginManager { * The module handler. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. + * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_manager + * The field type manager. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManager $field_type_manager) { $annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); parent::__construct('Plugin/field/widget', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldWidget'); @@ -52,6 +62,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac $this->alterInfo($module_handler, 'field_widget_info'); $this->factory = new WidgetFactory($this); + $this->fieldTypeManager = $field_type_manager; } /** @@ -93,7 +104,7 @@ public function getInstance(array $options) { $definition = $this->getDefinition($configuration['type']); if (!isset($definition['class']) || !in_array($field_type, $definition['field_types'])) { // Grab the default widget for the field type. - $field_type_definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_type); + $field_type_definition = $this->fieldTypeManager->getDefinition($field_type); $plugin_id = $field_type_definition['default_widget']; } @@ -137,7 +148,7 @@ public function prepareConfiguration($field_type, array $configuration) { ); // If no widget is specified, use the default widget. if (!isset($configuration['type'])) { - $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_type); + $field_type = $this->fieldTypeManager->getDefinition($field_type); $configuration['type'] = $field_type['default_widget']; } // Fill in default settings values for the widget. @@ -160,7 +171,7 @@ public function prepareConfiguration($field_type, array $configuration) { public function getOptions($field_type = NULL) { if (!isset($this->widgetOptions)) { $options = array(); - $field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions(); + $field_types = $this->fieldTypeManager->getDefinitions(); $widget_types = $this->getDefinitions(); uasort($widget_types, 'drupal_sort_weight'); foreach ($widget_types as $name => $widget_type) { diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index ca5ce68..8f5c630 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -279,8 +279,9 @@ function testFieldMap() { function testSettingsInfo() { $info = field_test_field_info(); foreach ($info as $type => $data) { - $this->assertIdentical(\Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings($type), $data['settings'], format_string("field settings service returns %type's field settings", array('%type' => $type))); - $this->assertIdentical(\Drupal::service('plugin.manager.entity.field.field_type')->getDefaultInstanceSettings($type), $data['instance_settings'], format_string("field instance settings service returns %type's field instance settings", array('%type' => $type))); + $field_type_manager = \Drupal::service('plugin.manager.entity.field.field_type'); + $this->assertIdentical($field_type_manager->getDefaultSettings($type), $data['settings'], format_string("field settings service returns %type's field settings", array('%type' => $type))); + $this->assertIdentical($field_type_manager->getDefaultInstanceSettings($type), $data['instance_settings'], format_string("field instance settings service returns %type's field instance settings", array('%type' => $type))); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php index 359e56e..22fb826 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\Entity\ConfigEntityListController; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\field\FieldInfo; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -48,6 +49,13 @@ class FieldListController extends ConfigEntityListController { protected $bundles; /** + * The field type manager. + * + * @var \Drupal\Core\Entity\Field\FieldTypePluginManager + */ + protected $fieldTypeManager; + + /** * Constructs a new EntityListController object. * * @param string $entity_type @@ -61,13 +69,14 @@ class FieldListController extends ConfigEntityListController { * @param \Drupal\field\FieldInfo $field_info * The field info service. */ - public function __construct($entity_type, array $entity_info, EntityManager $entity_manager, ModuleHandlerInterface $module_handler, FieldInfo $field_info) { + public function __construct($entity_type, array $entity_info, EntityManager $entity_manager, ModuleHandlerInterface $module_handler, FieldInfo $field_info, FieldTypePluginManager $field_type_manager) { parent::__construct($entity_type, $entity_info, $entity_manager->getStorageController($entity_type), $module_handler); - $this->fieldTypes = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions(); + $this->fieldTypes = $this->fieldTypeManager->getDefinitions(); $this->fieldInfo = $field_info->getFieldMap(); $this->entityManager = $entity_manager; $this->bundles = entity_get_bundles(); + $this->fieldTypeManager = $field_type_manager; } /** @@ -79,7 +88,8 @@ public static function createInstance(ContainerInterface $container, $entity_typ $entity_info, $container->get('plugin.manager.entity'), $container->get('module_handler'), - $container->get('field.info') + $container->get('field.info'), + $container->get('plugin.manager.entity.field.field_type') ); } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index fb13fd8..d4c392c 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -7,6 +7,8 @@ namespace Drupal\field_ui; +use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\field_ui\OverviewBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\field\Plugin\Core\Entity\Field; @@ -17,6 +19,36 @@ class FieldOverview extends OverviewBase { /** + * The field type manager. + * + * @var \Drupal\Core\Entity\Field\FieldTypePluginManager + */ + protected $fieldTypeManager; + + /** + * Constructs a new FieldOverview. + * + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager. + * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_manager + * The field type manager + */ + public function __construct(EntityManager $entity_manager, FieldTypePluginManager $field_type_manager) { + $this->entityManager = $entity_manager; + $this->fieldTypeManager = $field_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity'), + $container->get('plugin.manager.entity.field.field_type') + ); + } + + /** * {@inheritdoc} */ public function getRegions() { @@ -45,7 +77,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, // Gather bundle information. $instances = field_info_instances($this->entity_type, $this->bundle); - $field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions(); + $field_types = $this->fieldTypeManager->getDefinitions(); // Field prefix. $field_prefix = config('field_ui.settings')->get('field_prefix'); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index bc9ab7b..c311f74 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -222,7 +222,7 @@ protected function getDefaultValueWidget($field, array &$form, &$form_state) { // @todo Clean this up since we don't have $this->instance['widget'] anymore. // see https://drupal.org/node/2028759 if ($this->instance['widget']['type'] == 'hidden') { - $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field['type']); + $field_type = $this->fieldTypeManager->getDefinition($field['type']); $default_widget = $this->widgetManager->getDefinition($field_type['default_widget']); $this->instance['widget'] = array( diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php index 5f7ca61..8f713b0 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceFormBase.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormInterface; use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\field\Plugin\Type\Widget\WidgetPluginManager; use Drupal\field\FieldInstanceInterface; use Drupal\field_ui\FieldUI; @@ -39,16 +40,26 @@ protected $entityManager; /** + * The field type manager. + * + * @var \Drupal\Core\Entity\Field\FieldTypePluginManager + */ + protected $fieldTypeManager; + + /** * Constructs a new field instance form. * * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager. * @param \Drupal\field\Plugin\Type\Widget\WidgetPluginManager $widget_manager * The field widget plugin manager. + * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_manager + * The field type manager */ - public function __construct(EntityManager $entity_manager, WidgetPluginManager $widget_manager) { + public function __construct(EntityManager $entity_manager, WidgetPluginManager $widget_manager ,FieldTypePluginManager $field_type_manager) { $this->entityManager = $entity_manager; $this->widgetManager = $widget_manager; + $this->fieldTypeManager = $field_type_manager; } /** @@ -57,7 +68,8 @@ public function __construct(EntityManager $entity_manager, WidgetPluginManager $ public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.entity'), - $container->get('plugin.manager.field.widget') + $container->get('plugin.manager.field.widget'), + $container->get('plugin.manager.entity.field.field_type') ); }