summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-10-19 08:32:02 (GMT)
committerAlex Pott2013-10-19 08:32:02 (GMT)
commit00249dba68e40dcde61bc00a6b9e7549aaddc220 (patch)
tree69481c1b49e1d1451e942f4deea732976f0c99a4
parent3ded2216b02adea6bfd50dd994fdbe1c12706cd9 (diff)
Issue #2011082 by jiff, phiit, swentel, pfrenssen: Replace drupal_container() with Drupal::service() in the field module.
-rw-r--r--core/modules/field/field.deprecated.inc8
-rw-r--r--core/modules/field/field.module2
-rw-r--r--core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php45
-rw-r--r--core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php32
4 files changed, 63 insertions, 24 deletions
diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc
index fe8831f..db6f339 100644
--- a/core/modules/field/field.deprecated.inc
+++ b/core/modules/field/field.deprecated.inc
@@ -87,10 +87,10 @@ function field_info_instance_settings($type) {
*/
function field_info_widget_types($widget_type = NULL) {
if ($widget_type) {
- return drupal_container()->get('plugin.manager.field.widget')->getDefinition($widget_type);
+ return \Drupal::service('plugin.manager.field.widget')->getDefinition($widget_type);
}
else {
- return drupal_container()->get('plugin.manager.field.widget')->getDefinitions();
+ return \Drupal::service('plugin.manager.field.widget')->getDefinitions();
}
}
@@ -131,10 +131,10 @@ function field_info_widget_settings($type) {
*/
function field_info_formatter_types($formatter_type = NULL) {
if ($formatter_type) {
- return drupal_container()->get('plugin.manager.field.formatter')->getDefinition($formatter_type);
+ return \Drupal::service('plugin.manager.field.formatter')->getDefinition($formatter_type);
}
else {
- return drupal_container()->get('plugin.manager.field.formatter')->getDefinitions();
+ return \Drupal::service('plugin.manager.field.formatter')->getDefinitions();
}
}
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index cea8e78..2f0de84 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -529,7 +529,7 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options
// hook_field_attach_display_alter() needs to receive the 'prepared'
// $display_options, so we cannot let preparation happen internally.
$field = field_info_field($entity_type, $field_name);
- $formatter_manager = drupal_container()->get('plugin.manager.field.formatter');
+ $formatter_manager = Drupal::service('plugin.manager.field.formatter');
$display_options = $formatter_manager->prepareConfiguration($field->getFieldType(), $display_options);
$formatter = $formatter_manager->getInstance(array(
'field_definition' => $instance,
diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
index 7292202..995bc9e 100644
--- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
+++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php
@@ -7,17 +7,17 @@
namespace Drupal\field\Plugin\views\field;
-use Drupal\Core\Entity\FieldableDatabaseStorageController;
use Drupal\Core\Entity\EntityInterface;
-use Drupal\Core\Entity\EntityStorageControllerInterface;
-use Drupal\Core\Language\Language;
use Drupal\Core\Entity\EntityManager;
+use Drupal\Core\Entity\EntityStorageControllerInterface;
+use Drupal\Core\Entity\FieldableDatabaseStorageController;
use Drupal\Core\Field\FormatterPluginManager;
+use Drupal\Core\Language\Language;
+use Drupal\Core\Language\LanguageManager;
+use Drupal\views\Views;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
-use Drupal\Component\Annotation\PluginID;
-use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -86,6 +86,13 @@ class Field extends FieldPluginBase {
protected $formatterPluginManager;
/**
+ * The language manager.
+ *
+ * @var \Drupal\Core\Language\LanguageManager
+ */
+ protected $languageManager;
+
+ /**
* Constructs a \Drupal\field\Plugin\views\field\Field object.
*
* @param array $configuration
@@ -98,12 +105,15 @@ class Field extends FieldPluginBase {
* The field formatter plugin manager.
* @param \Drupal\Core\Field\FormatterPluginManager $formatter_plugin_manager
* The field formatter plugin manager.
+ * @param \Drupal\Core\Language\LanguageManager $language_manager
+ * The language manager.
*/
- public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityManager $entity_manager, FormatterPluginManager $formatter_plugin_manager) {
+ public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityManager $entity_manager, FormatterPluginManager $formatter_plugin_manager, LanguageManager $language_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityManager = $entity_manager;
$this->formatterPluginManager = $formatter_plugin_manager;
+ $this->languageManager = $language_manager;
}
/**
@@ -115,7 +125,8 @@ class Field extends FieldPluginBase {
$plugin_id,
$plugin_definition,
$container->get('entity.manager'),
- $container->get('plugin.manager.field.formatter')
+ $container->get('plugin.manager.field.formatter'),
+ $container->get('language_manager')
);
}
@@ -243,9 +254,11 @@ class Field extends FieldPluginBase {
// By the same reason as field_language the field might be Language::LANGCODE_NOT_SPECIFIED in reality so allow it as well.
// @see this::field_langcode()
$default_langcode = language_default()->id;
- $langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
- array(drupal_container()->get(Language::TYPE_CONTENT)->id, $default_langcode),
- $this->view->display_handler->options['field_langcode']);
+ $langcode = str_replace(
+ array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
+ array($this->languageManager->getLanguage(Language::TYPE_CONTENT)),
+ $this->view->display_handler->options['field_langcode']
+ );
$placeholder = $this->placeholder();
$langcode_fallback_candidates = array($langcode);
if (field_language_fallback_enabled()) {
@@ -441,7 +454,7 @@ class Field extends FieldPluginBase {
// Get the currently selected formatter.
$format = $this->options['type'];
- $settings = $this->options['settings'] + \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
+ $settings = $this->options['settings'] + $this->formatterPluginManager->getDefaultSettings($format);
$options = array(
'field_definition' => $field,
@@ -456,7 +469,7 @@ class Field extends FieldPluginBase {
// Get the settings form.
$settings_form = array('#value' => array());
- if ($formatter = drupal_container()->get('plugin.manager.field.formatter')->getInstance($options)) {
+ if ($formatter = $this->formatterPluginManager->getInstance($options)) {
$settings_form = $formatter->settingsForm($form, $form_state);
}
$form['settings'] = $settings_form;
@@ -847,9 +860,11 @@ class Field extends FieldPluginBase {
function field_langcode(EntityInterface $entity) {
if (field_is_translatable($entity->entityType(), $this->field_info)) {
$default_langcode = language_default()->id;
- $langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
- array(drupal_container()->get(Language::TYPE_CONTENT)->id, $default_langcode),
- $this->view->display_handler->options['field_language']);
+ $langcode = str_replace(
+ array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
+ array($this->languageManager->getLanguage(Language::TYPE_CONTENT)),
+ $this->view->display_handler->options['field_language']
+ );
// Give the Field Language API a chance to fallback to a different language
// (or Language::LANGCODE_NOT_SPECIFIED), in case the field has no data for the selected language.
diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php b/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php
index 3103945..16c5f92 100644
--- a/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php
+++ b/core/modules/field/lib/Drupal/field/Plugin/views/relationship/EntityReverse.php
@@ -7,11 +7,12 @@
namespace Drupal\field\Plugin\views\relationship;
-use Drupal\views\ViewExecutable;
+use Drupal\views\Plugin\ViewsHandlerManager;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\relationship\RelationshipPluginBase;
-use Drupal\Component\Annotation\PluginID;
+use Drupal\views\ViewExecutable;
use Drupal\views\Views;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* A relationship handlers which reverse entity references.
@@ -23,6 +24,29 @@ use Drupal\views\Views;
class EntityReverse extends RelationshipPluginBase {
/**
+ * Constructs an EntityReverse object.
+ *
+ * @param \Drupal\views\Plugin\ViewsHandlerManager $join_manager
+ * The views plugin join manager.
+ */
+ public function __construct(array $configuration, $plugin_id, array $plugin_definition, ViewsHandlerManager $join_manager) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition);
+ $this->joinManager = $join_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
+ return new static(
+ $configuration,
+ $plugin_id,
+ $plugin_definition,
+ $container->get('plugin.manager.views.join')
+ );
+ }
+
+ /**
* Overrides \Drupal\views\Plugin\views\relationship\RelationshipPluginBase::init().
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
@@ -62,7 +86,7 @@ class EntityReverse extends RelationshipPluginBase {
else {
$id = 'standard';
}
- $first_join = drupal_container()->get('plugin.manager.views.join')->createInstance($id, $first);
+ $first_join = $this->joinManager->createInstance($id, $first);
$this->first_alias = $this->query->addTable($this->definition['field table'], $this->relationship, $first_join);
@@ -87,7 +111,7 @@ class EntityReverse extends RelationshipPluginBase {
else {
$id = 'standard';
}
- $second_join = drupal_container()->get('plugin.manager.views.join')->createInstance($id, $second);
+ $second_join = $this->joinManager->createInstance($id, $second);
$second_join->adjusted = TRUE;
// use a short alias for this: