Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
294
Merge Requests
294
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
1c177411
Commit
1c177411
authored
Aug 01, 2013
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2047993
by plopesc: Remove current uses of field_info_*_types() / field_info_*_settings().
parent
63d299d9
Changes
32
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
212 additions
and
99 deletions
+212
-99
core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php
core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php
+30
-0
core/modules/edit/edit.services.yml
core/modules/edit/edit.services.yml
+1
-1
core/modules/edit/lib/Drupal/edit/EditorSelector.php
core/modules/edit/lib/Drupal/edit/EditorSelector.php
+13
-2
core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
...odules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
+1
-1
core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php
...ules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php
+1
-1
core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
...es/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
+2
-2
core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
...ules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
+4
-4
core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php
.../entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php
+4
-4
core/modules/entity_reference/entity_reference.module
core/modules/entity_reference/entity_reference.module
+1
-1
core/modules/field/field.info.inc
core/modules/field/field.info.inc
+13
-21
core/modules/field/field.module
core/modules/field/field.module
+1
-1
core/modules/field/field.services.yml
core/modules/field/field.services.yml
+3
-3
core/modules/field/field.views.inc
core/modules/field/field.views.inc
+1
-1
core/modules/field/lib/Drupal/field/FieldInfo.php
core/modules/field/lib/Drupal/field/FieldInfo.php
+14
-3
core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php
...dules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php
+3
-3
core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php
...eld/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php
+1
-1
core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php
...al/field/Plugin/Type/Formatter/FormatterPluginManager.php
+16
-5
core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php
...b/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php
+16
-5
core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
...dules/field/lib/Drupal/field/Plugin/views/field/Field.php
+2
-2
core/modules/field/lib/Drupal/field/Tests/CrudTest.php
core/modules/field/lib/Drupal/field/Tests/CrudTest.php
+1
-1
core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php
core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php
+2
-2
core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php
+7
-16
core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php
...es/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php
+1
-1
core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php
...ules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php
+1
-1
core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php
...ules/field_ui/lib/Drupal/field_ui/FieldListController.php
+15
-3
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+34
-2
core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
...eld_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
+15
-3
core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
.../field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
+5
-5
core/modules/file/file.field.inc
core/modules/file/file.field.inc
+1
-1
core/modules/image/image.field.inc
core/modules/image/image.field.inc
+1
-1
core/modules/node/node.tokens.inc
core/modules/node/node.tokens.inc
+1
-1
core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php
.../Drupal/options/Plugin/field/widget/OptionsWidgetBase.php
+1
-1
No files found.
core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php
View file @
1c177411
...
...
@@ -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
();
}
}
core/modules/edit/edit.services.yml
View file @
1c177411
...
...
@@ -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'
]
core/modules/edit/lib/Drupal/edit/EditorSelector.php
View file @
1c177411
...
...
@@ -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
;
...
...
core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
View file @
1c177411
...
...
@@ -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'
)
);
}
/**
...
...
core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php
View file @
1c177411
...
...
@@ -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
);
}
...
...
core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
View file @
1c177411
...
...
@@ -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.
...
...
core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php
View file @
1c177411
...
...
@@ -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.
...
...
core/modules/entity/lib/Drupal/entity/Tests/EntityFormDisplayTest.php
View file @
1c177411
...
...
@@ -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.
...
...
core/modules/entity_reference/entity_reference.module
View file @
1c177411
...
...
@@ -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
();
}
...
...
core/modules/field/field.info.inc
View file @
1c177411
...
...
@@ -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
);
}
/**
...
...
core/modules/field/field.module
View file @
1c177411
...
...
@@ -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_type
s
());
$info
[
'hidden'
][
'field_types'
]
=
array_keys
(
\
Drupal
::
service
(
'plugin.manager.entity.field.field_type'
)
->
getDefinition
s
());
}
/**
...
...
core/modules/field/field.services.yml
View file @
1c177411
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
:
...
...
core/modules/field/field.views.inc
View file @
1c177411
...
...
@@ -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_type
s
();
$field_types
=
\
Drupal
::
service
(
'plugin.manager.entity.field.field_type'
)
->
getDefinition
s
();
// Check the field module is available.
if
(
!
isset
(
$field_types
[
$field
[
'type'
]]))
{
...
...
core/modules/field/lib/Drupal/field/FieldInfo.php
View file @
1c177411
...
...
@@ -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_s
ettings
(
$field
[
'type'
]);
$field
[
'settings'
]
+=
$this
->
fieldTypeManager
->
getDefaultS
ettings
(
$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_s
ettings
(
$field_type
);
$instance
[
'settings'
]
+=
$this
->
fieldTypeManager
->
getDefaultInstanceS
ettings
(
$field_type
);
// Set a default value for the instance.
if
(
field_behaviors_widget
(
'default value'
,
$instance
)
==
FIELD_BEHAVIOR_DEFAULT
&&
!
isset
(
$instance
[
'default_value'
]))
{
...
...
core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php
View file @
1c177411
...
...
@@ -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.
...
...
core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php
View file @
1c177411
...
...
@@ -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'
];
...
...
core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php
View file @
1c177411
...
...
@@ -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_s
ettings
(
$configuration
[
'type'
]);
$configuration
[
'settings'
]
+=
$this
->
getDefaultS
ettings
(
$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_type
s
();
$field_types
=
$this
->
fieldTypeManager
->
getDefinition
s
();
$options
=
array
();
foreach
(
$this
->
getDefinitions
()
as
$name
=>
$formatter
)
{
foreach
(
$formatter
[
'field_types'
]
as
$formatter_field_type
)
{
...
...
core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php
View file @
1c177411
...
...
@@ -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_s
ettings
(
$configuration
[
'type'
]);
$configuration
[
'settings'
]
+=
$this
->
getDefaultS
ettings
(
$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_type
s
();
$field_types
=
$this
->
fieldTypeManager
->
getDefinition
s
();
$widget_types
=
$this
->
getDefinitions
();
uasort
(
$widget_types
,
'drupal_sort_weight'
);
foreach
(
$widget_types
as
$name
=>
$widget_type
)
{
...
...
core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
View file @
1c177411
...
...
@@ -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_s
ettings
(
$format
);
$settings
=
$this
->
options
[
'settings'
]
+
\
Drupal
::
service
(
'plugin.manager.field.formatter'
)
->
getDefaultS
ettings
(
$format
);
$options
=
array
(
'field_definition'
=>
$field
,
...
...
core/modules/field/lib/Drupal/field/Tests/CrudTest.php
View file @
1c177411
...
...
@@ -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.
...
...
core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php
View file @
1c177411
...
...
@@ -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_s
ettings
(
'field_test_default'
);
$settings
=
\
Drupal
::
service
(
'plugin.manager.field.formatter'
)
->
getDefaultS
ettings
(
'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.