diff --git a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php index b97b196..0a360c6 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Entity; use Drupal\Core\Language\Language; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Entity form controller variant for content entity types. @@ -26,6 +27,23 @@ class ContentEntityFormController extends EntityFormController { /** * {@inheritdoc} */ + public static function create(ContainerInterface $container) { + return new static($container->get('entity.manager')); + } + + /** + * Constructs a ContentEntityFormController object. + * + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager. + */ + public function __construct(\Drupal\Core\Entity\EntityManager $entity_manager) { + $this->entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ public function form(array $form, array &$form_state) { $entity = $this->entity; // @todo Exploit the Field API to generate the default widgets for the @@ -94,7 +112,7 @@ public function getFormLangcode(array &$form_state) { // Imply a 'view' operation to ensure users edit entities in the same // language they are displayed. This allows to keep contextual editing // working also for multilingual entities. - $form_state['langcode'] = $this->entityManager()->getTranslationFromContext($this->entity)->language()->id; + $form_state['langcode'] = $this->entityManager->getTranslationFromContext($this->entity)->language()->id; } return $form_state['langcode']; } @@ -141,17 +159,4 @@ public function buildEntity(array $form, array &$form_state) { return $entity; } - /** - * Gets the entity manager. - * - * @return \Drupal\Core\Entity\EntityManager - * The entity manager. - */ - protected function entityManager() { - if (!$this->entityManager) { - $this->entityManager = $this->container()->get('entity.manager'); - } - return $this->entityManager; - } - } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 1bcaed2..ad5d39d 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -475,7 +475,7 @@ public function getEntityTypeLabels() { * @return \Drupal\Core\Entity\ContentEntityInterface * A content entity object for the translated data. * - * @see \Drupal\Core\Language\LanguageManager::getCandidateLangcodes() + * @see \Drupal\Core\Language\LanguageManager::getFallbackCandidates() */ function getTranslationFromContext(ContentEntityInterface $entity, $langcode = NULL, $context = array()) { $translation = $entity; @@ -488,7 +488,7 @@ function getTranslationFromContext(ContentEntityInterface $entity, $langcode = N // negotiation. $context['data'] = $entity; $context += array('operation' => 'entity_view'); - $candidates = $this->languageManager->getCandidateLangcodes($langcode, $context); + $candidates = $this->languageManager->getFallbackCandidates($langcode, $context); // Ensure the default language has the proper language code. $default_language = $entity->getUntranslated()->language(); diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index dc51ae9..532d404 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -191,7 +191,7 @@ public function isMultilingual() { * An array of language codes sorted by priority: first values should be * tried first. */ - public function getCandidateLangcodes($langcode = NULL, array $context = array()) { + public function getFallbackCandidates($langcode = NULL, array $context = array()) { if ($this->isMultilingual()) { // Get languages ordered by weight, add Language::LANGCODE_NOT_SPECIFIED at // the end. diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index 388bc62..8ac2bc2 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -914,7 +914,7 @@ function field_valid_language($langcode, $default = TRUE) { * A language code if a field name is specified, an array of language codes * keyed by field name otherwise. * - * @see \Drupal\Core\Language\LanguageManager::getCandidateLangcodes() + * @see \Drupal\Core\Language\LanguageManager::getFallbackCandidates() * @see \Drupal\Core\Entity\EntityInterface::getFieldLangcode() * * @deprecated This has been deprecated in favor of the Entity Field API. 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 5f60c82..e669873 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 @@ -261,7 +261,7 @@ public function query($use_groupby = FALSE) { $this->view->display_handler->options['field_langcode'] ); $placeholder = $this->placeholder(); - $langcode_fallback_candidates = $this->languageManager->getCandidateLangcodes(array('operation' => 'views_query', 'langcode' => $langcode, 'data' => $this)); + $langcode_fallback_candidates = $this->languageManager->getFallbackCandidates(array('operation' => 'views_query', 'langcode' => $langcode, 'data' => $this)); $this->query->addWhereExpression(0, "$column IN($placeholder) OR $column IS NULL", array($placeholder => $langcode_fallback_candidates)); } } diff --git a/core/modules/language/language.api.php b/core/modules/language/language.api.php index facdda9..d0a31c4 100644 --- a/core/modules/language/language.api.php +++ b/core/modules/language/language.api.php @@ -66,7 +66,7 @@ function hook_language_delete($language) { * @param array $context * A language fallback context. * - * @see \Drupal\Core\Language\LanguageManager::getCandidateLangcodes() + * @see \Drupal\Core\Language\LanguageManager::getFallbackCandidates() */ function hook_language_fallback_candidates_alter(array &$candidates, array $context) { $candidates = array_reverse($candidates); @@ -81,7 +81,7 @@ function hook_language_fallback_candidates_alter(array &$candidates, array $cont * @param array $context * A language fallback context. * - * @see \Drupal\Core\Language\LanguageManager::getCandidateLangcodes() + * @see \Drupal\Core\Language\LanguageManager::getFallbackCandidates() */ function hook_language_fallback_candidates_OPERATION_alter(array &$candidates, array $context) { // We know that the current OPERATION deals with entities so no need to check diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php index e00ba78..ba50def 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php @@ -58,13 +58,13 @@ public function testCandidates() { // Check that language fallback candidates by default are all the available // languages sorted by weight. - $candidates = $manager->getCandidateLangcodes(); + $candidates = $manager->getFallbackCandidates(); $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are properly returned.'); // Check that candidates are alterable. $this->state->set('language_test.fallback_alter.candidates', TRUE); $expected = array_slice($expected, 0, count($expected) - 1); - $candidates = $manager->getCandidateLangcodes(); + $candidates = $manager->getFallbackCandidates(); $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable.'); // Check that candidates are alterable for specific operations. @@ -72,7 +72,7 @@ public function testCandidates() { $this->state->set('language_test.fallback_operation_alter.candidates', TRUE); $expected[] = Language::LANGCODE_NOT_SPECIFIED; $expected[] = Language::LANGCODE_NOT_APPLICABLE; - $candidates = $manager->getCandidateLangcodes(NULL, array('operation' => 'test')); + $candidates = $manager->getFallbackCandidates(NULL, array('operation' => 'test')); $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.'); // Check that when the site is monolingual no language fallback is applied. @@ -82,7 +82,7 @@ public function testCandidates() { language_delete($langcode); } } - $candidates = $this->getLanguageManager()->getCandidateLangcodes(); + $candidates = $this->getLanguageManager()->getFallbackCandidates(); $this->assertEqual(array_values($candidates), array(Language::LANGCODE_DEFAULT), 'Language fallback is not applied when the Language module is not enabled.'); }