Commit 00249dba authored by alexpott's avatar alexpott

Issue #2011082 by jiff, phiit, swentel, pfrenssen: Replace drupal_container()...

Issue #2011082 by jiff, phiit, swentel, pfrenssen: Replace drupal_container() with Drupal::service() in the field module.
parent 3ded2216
......@@ -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();
}
}
......
......@@ -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,
......
......@@ -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;
/**
......@@ -85,6 +85,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.
*
......@@ -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 @@ public static function create(ContainerInterface $container, array $configuratio
$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 @@ public function query($use_groupby = FALSE) {
// 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 @@ public function buildOptionsForm(&$form, &$form_state) {
// 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 @@ public function buildOptionsForm(&$form, &$form_state) {
// 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 @@ protected function addSelfTokens(&$tokens, $item) {
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.
......
......@@ -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.
......@@ -22,6 +23,29 @@
*/
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().
*/
......@@ -62,7 +86,7 @@ public function query() {
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 @@ public function query() {
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:
......
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