diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 68be002..c4e9c7e 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -389,6 +389,8 @@ public function calculateDependencies() { * {@inheritdoc} */ public function urlInfo($rel = 'edit-form', array $options = []) { + // Unless language was already provided, avoid setting an explicit language. + $options += ['language' => NULL]; return parent::urlInfo($rel, $options); } diff --git a/core/modules/views/src/Plugin/views/field/EntityOperations.php b/core/modules/views/src/Plugin/views/field/EntityOperations.php index 35fbfc3..c766980 100644 --- a/core/modules/views/src/Plugin/views/field/EntityOperations.php +++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php @@ -9,7 +9,9 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Routing\RedirectDestinationTrait; +use Drupal\views\Entity\Render\EntityTranslationRenderTrait; use Drupal\views\ResultRow; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -22,6 +24,7 @@ */ class EntityOperations extends FieldPluginBase { + use EntityTranslationRenderTrait; use RedirectDestinationTrait; /** @@ -32,6 +35,13 @@ class EntityOperations extends FieldPluginBase { protected $entityManager; /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** * Constructor. * * @param array $configuration @@ -42,10 +52,14 @@ class EntityOperations extends FieldPluginBase { * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityManagerInterface $entity_manager) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->entityManager = $entity_manager; + $this->languageManager = $language_manager; } /** @@ -56,7 +70,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('entity.manager') + $container->get('entity.manager'), + $container->get('language_manager') ); } @@ -98,7 +113,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function render(ResultRow $values) { - $entity = $this->getEntity($values); + $entity = $this->getEntityTranslation($this->getEntity($values), $values); $operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity); if ($this->options['destination']) { foreach ($operations as &$operation) { @@ -120,8 +135,38 @@ public function render(ResultRow $values) { * {@inheritdoc} */ public function query() { - // There is nothing to ensure or add for this handler, so we purposefully do - // nothing here and do not call parent::query() either. + // There is nothing to ensure or add for this handler other than language, + // so we purposefully do not call parent::query(). + if ($this->languageManager->isMultilingual()) { + $this->getEntityTranslationRenderer()->query($this->query, $this->relationship); + } + } + + /** + * {@inheritdoc} + */ + public function getEntityTypeId() { + return $this->getEntityType(); + } + + /** + * {@inheritdoc} + */ + protected function getEntityManager() { + return $this->entityManager; + } + + /** + * {@inheritdoc} + */ + protected function getLanguageManager() { + return $this->languageManager; + } + /** + * {@inheritdoc} + */ + protected function getView() { + return $this->view; } } diff --git a/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php b/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php index c7c7002..7300118 100644 --- a/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php @@ -25,6 +25,13 @@ class EntityOperationsUnitTest extends UnitTestCase { protected $entityManager; /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $languageManager; + + /** * The plugin under test. * * @var \Drupal\views\Plugin\views\field\EntityOperations @@ -38,13 +45,14 @@ class EntityOperationsUnitTest extends UnitTestCase { */ public function setUp() { $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->languageManager = $this->getMock('\Drupal\Core\Language\LanguageManagerInterface'); $configuration = array(); $plugin_id = $this->randomMachineName(); $plugin_definition = array( 'title' => $this->randomMachineName(), ); - $this->plugin = new EntityOperations($configuration, $plugin_id, $plugin_definition, $this->entityManager); + $this->plugin = new EntityOperations($configuration, $plugin_id, $plugin_definition, $this->entityManager, $this->languageManager); $redirect_service = $this->getMock('Drupal\Core\Routing\RedirectDestinationInterface'); $redirect_service->expects($this->any()) diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php index 8b9852c..6b67975 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php @@ -66,10 +66,13 @@ public function testUrlInfo($entity_class, $link_template, $expected, $langcode $this->assertEquals($langcode, $uri->getOption('language')->getId()); } else { - // The expected langcode for a config entity is 'en', because it sets the - // value as default property. - $expected_langcode = $entity instanceof ConfigEntityInterface ? 'en' : LanguageInterface::LANGCODE_NOT_SPECIFIED; - $this->assertEquals($expected_langcode, $uri->getOption('language')->getId()); + if ($entity instanceof ConfigEntityInterface) { + // Config entities do not provide a language with their URIs. + $this->assertEquals(NULL, $uri->getOption('language')); + } + else { + $this->assertEquals(LanguageInterface::LANGCODE_NOT_SPECIFIED, $uri->getOption('language')->getId()); + } } }