Commit 1c177411 authored by catch's avatar catch

Issue #2047993 by plopesc: Remove current uses of field_info_*_types() / field_info_*_settings().

parent 63d299d9
......@@ -54,4 +54,34 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
$this->discovery = new LegacyFieldTypeDiscoveryDecorator($this->discovery, $module_handler);
}
/**
* Returns the default field-level settings for a field type.
*
* @param string $type
* A field type name.
*
* @return array
* The type's default settings, as provided by the plugin
* definition, or an empty array if type or settings are undefined.
*/
public function getDefaultSettings($type) {
$info = $this->getDefinition($type);
return isset($info['settings']) ? $info['settings'] : array();
}
/**
* Returns the default instance-level settings for a field type.
*
* @param string $type
* A field type name.
*
* @return array
* The instance's default settings, as provided by the plugin
* definition, or an empty array if type or settings are undefined.
*/
public function getDefaultInstanceSettings($type) {
$info = $this->getDefinition($type);
return isset($info['instance_settings']) ? $info['instance_settings'] : array();
}
}
......@@ -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']
......@@ -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.
......@@ -23,6 +24,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.
*
......@@ -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 manager for formatter plugins.
*/
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 = field_info_formatter_types($formatter_type);
$formatter_info = $this->formatterManager->getDefinition($formatter_type);
$editor_id = $formatter_info['edit']['editor'];
if ($editor_id === 'disabled') {
return;
......
......@@ -41,7 +41,7 @@ function setUp() {
parent::setUp();
$this->editorManager = $this->container->get('plugin.manager.edit.editor');
$this->editorSelector = new EditorSelector($this->editorManager);
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
}
/**
......
......@@ -59,7 +59,7 @@ function setUp() {
$this->editorManager = $this->container->get('plugin.manager.edit.editor');
$this->accessChecker = new MockEditEntityFieldAccessCheck();
$this->editorSelector = new EditorSelector($this->editorManager);
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
}
......
......@@ -124,7 +124,7 @@ protected function getSelectedEditor($items, $field_name, $view_mode = 'default'
*/
function testEditorSelection() {
$this->editorManager = new InPlaceEditorManager($this->container->get('container.namespaces'));
$this->editorSelector = new EditorSelector($this->editorManager);
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
// Pretend there is an entity with these items for the field.
$items = array(array('value' => 'Hello, world!', 'format' => 'filtered_html'));
......@@ -149,7 +149,7 @@ function testEditorSelection() {
function testMetadata() {
$this->editorManager = new InPlaceEditorManager($this->container->get('container.namespaces'));
$this->accessChecker = new MockEditEntityFieldAccessCheck();
$this->editorSelector = new EditorSelector($this->editorManager);
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
// Create an entity with values for the field.
......
......@@ -155,21 +155,21 @@ public function testFieldComponent() {
// Check that providing no options results in default values being used.
$display->setComponent($field_name);
$field_type_info = field_info_field_types($field->type);
$field_type_info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field->type);
$default_formatter = $field_type_info['default_formatter'];
$default_settings = field_info_formatter_settings($default_formatter);
$formatter_settings = \Drupal::service('plugin.manager.field.formatter')->getDefinition($default_formatter);
$expected = array(
'weight' => 0,
'label' => 'above',
'type' => $default_formatter,
'settings' => $default_settings,
'settings' => $formatter_settings['settings'],
);
$this->assertEqual($display->getComponent($field_name), $expected);
// Check that the getFormatter() method returns the correct formatter plugin.
$formatter = $display->getRenderer($field_name);
$this->assertEqual($formatter->getPluginId(), $default_formatter);
$this->assertEqual($formatter->getSettings(), $default_settings);
$this->assertEqual($formatter->getSettings(), $formatter_settings['settings']);
// Check that the formatter is statically persisted, by assigning an
// arbitrary property and reading it back.
......
......@@ -77,20 +77,20 @@ public function testFieldComponent() {
// Check that providing no options results in default values being used.
$form_display->setComponent($field_name);
$field_type_info = field_info_field_types($field->type);
$field_type_info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field->type);
$default_widget = $field_type_info['default_widget'];
$default_settings = field_info_widget_settings($default_widget);
$widget_settings = \Drupal::service('plugin.manager.field.widget')->getDefinition($default_widget);
$expected = array(
'weight' => 0,
'type' => $default_widget,
'settings' => $default_settings,
'settings' => $widget_settings['settings'],
);
$this->assertEqual($form_display->getComponent($field_name), $expected);
// Check that the getWidget() method returns the correct widget plugin.
$widget = $form_display->getRenderer($field_name);
$this->assertEqual($widget->getPluginId(), $default_widget);
$this->assertEqual($widget->getSettings(), $default_settings);
$this->assertEqual($widget->getSettings(), $widget_settings['settings']);
// Check that the widget is statically persisted, by assigning an
// arbitrary property and reading it back.
......
......@@ -389,7 +389,7 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query
*/
function entity_reference_create_instance($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array()) {
// If a field type we know should exist isn't found, clear the field cache.
if (!field_info_field_types('entity_reference')) {
if (!\Drupal::service('plugin.manager.entity.field.field_type')->getDefinition('entity_reference')) {
field_cache_clear();
}
......
......@@ -130,7 +130,7 @@ function _field_info_collate_types_reset() {
function field_behaviors_widget($op, $instance) {
$info = array();
if ($component = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($instance['field_name'])) {
$info = field_info_widget_types($component['type']);
$info = \Drupal::service('plugin.manager.field.widget')->getDefinition($component['type']);
}
return isset($info[$op]) ? $info[$op] : FIELD_BEHAVIOR_DEFAULT;
}
......@@ -503,13 +503,11 @@ function field_info_extra_fields($entity_type, $bundle, $context) {
* The field type's default settings, or an empty array if type or settings
* are not defined.
*
* @deprecated as of Drupal 8.0. Use the 'settings' property in the definition
* array returned by
* Drupal::service('plugin.manager.entity.field.field_type')->getDefinition()
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings()
*/
function field_info_field_settings($type) {
$info = field_info_field_types($type);
return isset($info['settings']) ? $info['settings'] : array();
return \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultSettings($type);
}
/**
......@@ -522,13 +520,11 @@ function field_info_field_settings($type) {
* The field type's default instance settings, or an empty array if type or
* settings are not defined.
*
* @deprecated as of Drupal 8.0. Use the 'instance_settings' property in the
* definition array returned by
* Drupal::service('plugin.manager.entity.field.field_type')->getDefinition()
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.entity.field.field_type')->getDefaultInstanceSettings()
*/
function field_info_instance_settings($type) {
$info = field_info_field_types($type);
return isset($info['instance_settings']) ? $info['instance_settings'] : array();
return \Drupal::service('plugin.manager.entity.field.field_type')->getDefaultInstanceSettings($type);
}
/**
......@@ -542,13 +538,11 @@ function field_info_instance_settings($type) {
* hook_field_widget_info(), or an empty array if type or settings are
* undefined.
*
* @deprecated as of Drupal 8.0. Use the 'settings' property in the definition
* array returned by
* Drupal::service('plugin.manager.field.widget')->getDefinition()
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.field.widget')->getDefaultSettings()
*/
function field_info_widget_settings($type) {
$info = field_info_widget_types($type);
return isset($info['settings']) ? $info['settings'] : array();
return \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($type);
}
/**
......@@ -562,13 +556,11 @@ function field_info_widget_settings($type) {
* hook_field_formatter_info(), or an empty array if type or settings are
* undefined.
*
* @deprecated as of Drupal 8.0. Use the 'settings' property in the definition
* array returned by
* Drupal::service('plugin.manager.field.formatter')->getDefinition()
* @deprecated as of Drupal 8.0. Use
* Drupal::service('plugin.manager.field.formatter')->getDefaultSettings()
*/
function field_info_formatter_settings($type) {
$info = field_info_formatter_types($type);
return isset($info['settings']) ? $info['settings'] : array();
return \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($type);
}
/**
......
......@@ -328,7 +328,7 @@ function _field_generate_entity_field_definition(FieldInterface $field, FieldIns
*/
function field_field_widget_info_alter(&$info) {
// Add the Hidden widget to all field types.
$info['hidden']['field_types'] = array_keys(field_info_field_types());
$info['hidden']['field_types'] = array_keys(\Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions());
}
/**
......
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:
......
......@@ -90,7 +90,7 @@ function field_views_field_label($field_name) {
* Default views data implementation for a field.
*/
function field_views_field_default_views_data($field) {
$field_types = field_info_field_types();
$field_types = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
// Check the field module is available.
if (!isset($field_types[$field['type']])) {
......
......@@ -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;
/**
......@@ -44,6 +45,13 @@ class FieldInfo {
*/
protected $moduleHandler;
/**
* The field type manager to define field.
*
* @var \Drupal\Core\Entity\Field\FieldTypePluginManager
*/
protected $fieldTypeManager;
/**
* The config factory.
*
......@@ -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' plugin 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'] += field_info_field_settings($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'] += field_info_instance_settings($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'])) {
......
......@@ -352,7 +352,7 @@ protected function saveNew() {
}
// Check that the field type is known.
$field_type = field_info_field_types($this->type);
$field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->type);
if (!$field_type) {
throw new FieldException(format_string('Attempt to create a field of unknown type %type.', array('%type' => $this->type)));
}
......@@ -579,7 +579,7 @@ public function getFieldSettings() {
// maintains its own static cache. However, do some CPU and memory
// profiling to see if it's worth statically caching $field_type_info, or
// the default field and instance settings, within $this.
$field_type_info = field_info_field_types($this->type);
$field_type_info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->type);
$settings = $field_type_info['instance_settings'] + $this->settings + $field_type_info['settings'];
return $settings;
......@@ -590,7 +590,7 @@ public function getFieldSettings() {
*/
public function getFieldSetting($setting_name) {
// @todo See getFieldSettings() about potentially statically caching this.
$field_type_info = field_info_field_types($this->type);
$field_type_info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->type);
// We assume here that consecutive array_key_exists() is more efficient than
// calling getFieldSettings() when all we need is a single setting.
......
......@@ -425,7 +425,7 @@ protected function saveUpdated() {
* Prepares the instance definition for saving.
*/
protected function prepareSave() {
$field_type_info = field_info_field_types($this->field->type);
$field_type_info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->field->type);
// Set the default instance settings.
$this->settings += $field_type_info['instance_settings'];
......
......@@ -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;
......@@ -30,6 +31,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.
*
......@@ -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' plugin 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 = field_info_field_types($field_type);
$field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
$plugin_id = $field_type_definition['default_formatter'];
}
......@@ -142,11 +153,11 @@ public function prepareConfiguration($field_type, array $configuration) {
);
// If no formatter is specified, use the default formatter.
if (!isset($configuration['type'])) {
$field_type = field_info_field_types($field_type);
$field_type = $this->fieldTypeManager->getDefinition($field_type);
$configuration['type'] = $field_type['default_formatter'];
}
// Fill in default settings values for the formatter.
$configuration['settings'] += field_info_formatter_settings($configuration['type']);
$configuration['settings'] += $this->getDefaultSettings($configuration['type']);
return $configuration;
}
......@@ -163,7 +174,7 @@ public function prepareConfiguration($field_type, array $configuration) {
*/
public function getOptions($field_type = NULL) {
if (!isset($this->formatterOptions)) {
$field_types = field_info_field_types();
$field_types = $this->fieldTypeManager->getDefinitions();
$options = array();
foreach ($this->getDefinitions() as $name => $formatter) {
foreach ($formatter['field_types'] as $formatter_field_type) {
......
......@@ -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;
......@@ -23,6 +24,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.
*
......@@ -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' plugin 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 = field_info_field_types($field_type);
$field_type_definition = $this->fieldTypeManager->getDefinition($field_type);
$plugin_id = $field_type_definition['default_widget'];
}
......@@ -137,11 +148,11 @@ public function prepareConfiguration($field_type, array $configuration) {
);
// If no widget is specified, use the default widget.
if (!isset($configuration['type'])) {
$field_type = field_info_field_types($field_type);
$field_type = $this->fieldTypeManager->getDefinition($field_type);
$configuration['type'] = $field_type['default_widget'];
}
// Fill in default settings values for the widget.
$configuration['settings'] += field_info_widget_settings($configuration['type']);
$configuration['settings'] += $this->getDefaultSettings($configuration['type']);
return $configuration;
}
......@@ -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 = field_info_field_types();
$field_types = $this->fieldTypeManager->getDefinitions();
$widget_types = $this->getDefinitions();
uasort($widget_types, 'drupal_sort_weight');
foreach ($widget_types as $name => $widget_type) {
......
......@@ -299,7 +299,7 @@ protected function defineOptions() {
// defineOptions runs before init/construct, so no $this->field_info
$field = field_info_field($this->definition['field_name']);
$field_type = field_info_field_types($field['type']);
$field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field['type']);
$column_names = array_keys($field['columns']);
$default_column = '';
// Try to determine a sensible default.
......@@ -424,7 +424,7 @@ public function buildOptionsForm(&$form, &$form_state) {
// Get the currently selected formatter.
$format = $this->options['type'];
$settings = $this->options['settings'] + field_info_formatter_settings($format);
$settings = $this->options['settings'] + \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
$options = array(
'field_definition' => $field,
......
......@@ -60,7 +60,7 @@ function testCreateField() {
$this->assertEqual($field_config['cardinality'], 1, 'Cardinality defaults to 1.');
// Ensure that default settings are present.
$field_type = field_info_field_types($field_definition['type']);
$field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_definition['type']);
$this->assertEqual($field_config['settings'], $field_type['settings'], 'Default field settings have been written.');
// Ensure that default storage was set.
......
......@@ -121,7 +121,7 @@ function testFieldViewField() {
// No display settings: check that default display settings are used.
$output = field_view_field($this->entity, $this->field_name);
$this->content = drupal_render($output);
$settings = field_info_formatter_settings('field_test_default');
$settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings('field_test_default');
$setting = $settings['test_formatter_setting'];
$this->assertText($this->label, 'Label was displayed.');
foreach ($this->values as $delta => $value) {
......@@ -193,7 +193,7 @@ function testFieldViewField() {
*/
function testFieldViewValue() {
// No display settings: check that default display settings are used.
$settings = field_info_formatter_settings('field_test_default');
$settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings('field_test_default');
$setting = $settings['test_formatter_setting'];
foreach ($this->values as $delta => $value) {
$item = $this->entity->{$this->field_name}[$delta]->getValue();
......
......@@ -24,7 +24,7 @@ function testFieldInfo() {
// Test that field_test module's fields, widgets, and formatters show up.
$field_test_info = field_test_field_info();
$info = field_info_field_types();
$info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
foreach ($field_test_info as $t_key => $field_type) {
foreach ($field_type as $key => $val) {
$this->assertEqual($info[$t_key][$key], $val, format_string('Field type %t_key key %key is %value', array('%t_key' => $t_key, '%key' => $key, '%value' => print_r($val, TRUE))));
......@@ -139,7 +139,7 @@ function testFieldPrepare() {
$field = field_info_field($field_definition['field_name']);
// Check that all expected settings are in place.
$field_type = field_info_field_types($field_definition['type']);
$field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_definition['type']);
$this->assertEqual($field['settings'], $field_type['settings'], 'All expected default field settings are present.');
}
......@@ -172,7 +172,7 @@ function testInstancePrepare() {
$instance = field_info_instance($instance_definition['entity_type'], $instance_definition['field_name'], $instance_definition['bundle']);
// Check that all expected instance settings are in place.
$field_type = field_info_field_types($field_definition['type']);
$field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_definition['type']);
$this->assertEqual($instance['settings'], $field_type['instance_settings'] , 'All expected instance settings are present.');
}
......@@ -279,18 +279,9 @@ function testFieldMap() {
function testSettingsInfo() {
$info = field_test_field_info();
foreach ($info as $type => $data) {
$this->assertIdentical(field_info_field_settings($type), $data['settings'], format_string("field_info_field_settings returns %type's field settings", array('%type' => $type)));
$this->assertIdentical(field_info_instance_settings($type), $data['instance_settings'], format_string("field_info_field_settings returns %type's field instance settings", array('%type' => $type)));
}
foreach (array('test_field_widget', 'test_field_widget_multiple') as $type) {
$info = field_info_widget_types($type);
$this->assertIdentical(field_info_widget_settings($type), $info['settings'], format_string("field_info_widget_settings returns %type's widget settings", array('%type' => $type)));
}
foreach (array('field_test_default', 'field_test_multiple', 'field_test_with_prepare_view') as $type) {
$info = field_info_formatter_types($type);
$this->assertIdentical(field_info_formatter_settings($type), $info['settings'], format_string("field_info_formatter_settings returns %type's formatter 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)));
}
}
......@@ -323,7 +314,7 @@ function testFieldInfoCache() {
* Test that the widget definition functions work.
*/
function testWidgetDefinition() {
$widget_definition = field_info_widget_types('test_field_widget_multiple');
$widget_definition = \Drupal::service('plugin.manager.field.widget')->getDefinition('test_field_widget_multiple');
// Test if hook_field_widget_info_alter is beïng called.
$this->assertTrue(in_array('test_field', $widget_definition['field_types']), "The 'test_field_widget_multiple' widget is enabled for the 'test_field' field type in field_test_field_widget_info_alter().");
......
......@@ -74,7 +74,7 @@ function testCreateFieldInstance() {
// applied on write.
$config = \Drupal::config('field.instance.' . $instance->id())->get();
$field_type = field_info_field_types($this->field_definition['type']);
$field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->field_definition['type']);
// Check that default values are set.
$this->assertEqual($config['required'], FALSE, 'Required defaults to false.');
......
......@@ -45,7 +45,7 @@ public function __construct(EntityManager $entity_manager, PluginManagerBase $pl
parent::__construct($entity_manager);
$this->pluginManager = $plugin_manager;
$this->fieldTypes = field_info_field_types();
$this->fieldTypes = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions();
}
/**
......
......@@ -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;