Commit b28e80dd authored by catch's avatar catch

Issue #1831240 by yched: Register Field API plugin managers in the DIC.

parent b70ee4b4
......@@ -222,10 +222,10 @@ function field_info_field_types($field_type = NULL) {
*/
function field_info_widget_types($widget_type = NULL) {
if ($widget_type) {
return field_get_plugin_manager('widget')->getDefinition($widget_type);
return drupal_container()->get('plugin.manager.field.widget')->getDefinition($widget_type);
}
else {
return field_get_plugin_manager('widget')->getDefinitions();
return drupal_container()->get('plugin.manager.field.widget')->getDefinitions();
}
}
......@@ -243,10 +243,10 @@ function field_info_widget_types($widget_type = NULL) {
*/
function field_info_formatter_types($formatter_type = NULL) {
if ($formatter_type) {
return field_get_plugin_manager('formatter')->getDefinition($formatter_type);
return drupal_container()->get('plugin.manager.field.formatter')->getDefinition($formatter_type);
}
else {
return field_get_plugin_manager('formatter')->getDefinitions();
return drupal_container()->get('plugin.manager.field.formatter')->getDefinitions();
}
}
......
......@@ -543,36 +543,6 @@ function field_associate_fields($module) {
}
}
/**
* Returns the PluginManager object for a given field plugin type.
*
* @param string $plugin_type
* The plugin type. One of:
* - field_type
* - widget
* - formatter
* - storage
*
* @return Drupal\Component\Plugin\PluginManagerInterface
* The PluginManager object.
*/
function field_get_plugin_manager($plugin_type) {
$plugin_types = &drupal_static(__FUNCTION__, array());
$classes = array(
'widget' => 'Drupal\field\Plugin\Type\Widget\WidgetPluginManager',
'formatter' => 'Drupal\field\Plugin\Type\Formatter\FormatterPluginManager',
);
if (isset($classes[$plugin_type])) {
if (!isset($plugin_types[$plugin_type])) {
$plugin_types[$plugin_type] = new $classes[$plugin_type]();
}
return $plugin_types[$plugin_type];
}
}
/**
* Helper function to get the default value for a field on an entity.
*
......
<?php
/**
* @file
* Contains Drupal\field\FieldBundle.
*/
namespace Drupal\field;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Field dependency injection container.
*/
class FieldBundle extends Bundle {
/**
* Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build().
*/
public function build(ContainerBuilder $container) {
// Register the plugin managers for our plugin types with the dependency injection container.
$container->register('plugin.manager.field.widget', 'Drupal\field\Plugin\Type\Widget\WidgetPluginManager');
$container->register('plugin.manager.field.formatter', 'Drupal\field\Plugin\Type\Formatter\FormatterPluginManager');
}
}
......@@ -68,7 +68,7 @@ public function getWidget() {
'settings' => $widget_properties['settings'],
'weight' => $widget_properties['weight'],
);
$this->widget = field_get_plugin_manager('widget')->getInstance($options);
$this->widget = drupal_container()->get('plugin.manager.field.widget')->getInstance($options);
}
return $this->widget;
......@@ -142,7 +142,7 @@ public function getFormatter($display_properties) {
'weight' => $display_properties['weight'],
'view_mode' => $view_mode,
);
$formatter = field_get_plugin_manager('formatter')->getInstance($options);
$formatter = drupal_container()->get('plugin.manager.field.formatter')->getInstance($options);
}
else {
$formatter = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment