Commit 67692cbf authored by alexpott's avatar alexpott

Issue #2461013 by Berdir, keopx, Denchev, Gábor Hojtsy, xjm: Trying to display...

Issue #2461013 by Berdir, keopx, Denchev, Gábor Hojtsy, xjm: Trying to display not specified or not applicable languages with LanguageFormatter results in fatal error
parent 98459991
......@@ -12,6 +12,7 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -121,8 +122,8 @@ protected function viewValue(FieldItemInterface $item) {
// either displayed in its configured form (loaded directly from config
// storage by LanguageManager::getLanguages()) or in its native language
// name. That only depends on formatter settings and no language condition.
$languages = $this->getSetting('native_language') ? $this->languageManager->getNativeLanguages() : $this->languageManager->getLanguages();
return $item->language ? SafeMarkup::checkPlain($languages[$item->language->getId()]->getName()) : '';
$languages = $this->getSetting('native_language') ? $this->languageManager->getNativeLanguages(LanguageInterface::STATE_ALL) : $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
return $item->language && isset($languages[$item->language->getId()]) ? SafeMarkup::checkPlain($languages[$item->language->getId()]->getName()) : '';
}
}
......@@ -7,6 +7,7 @@
namespace Drupal\node\Tests\Views;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\views\Plugin\views\PluginBase;
......@@ -65,6 +66,9 @@ protected function setUp() {
// "English", or "Spanish", as there is a language field in the view
// that prints out those words.
$this->nodeTitles = array(
LanguageInterface::LANGCODE_NOT_SPECIFIED => array(
'First node und',
),
'es' => array(
'Primero nodo es',
'Segundo nodo es',
......@@ -90,6 +94,13 @@ protected function setUp() {
}
$node->save();
}
// Create non-translatable nodes.
foreach ($this->nodeTitles[LanguageInterface::LANGCODE_NOT_SPECIFIED] as $index => $title) {
$node = $this->drupalCreateNode(array('title' => $title, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'type' => 'page', 'promote' => 1));
$node->body->value = $this->randomMachineName(32);
$node->save();
}
$this->container->get('router.builder')->rebuild();
$user = $this->drupalCreateUser(array('access content overview', 'access content'));
......@@ -146,6 +157,10 @@ public function testLanguages() {
// Test the front page view filter. Only node titles in the current language
// should be displayed on the front page by default.
foreach ($this->nodeTitles as $langcode => $titles) {
// The frontpage view does not display content without a language.
if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
continue;
}
$this->drupalGet(($langcode == 'en' ? '' : "$langcode/") . 'node');
foreach ($titles as $title) {
$this->assertText($title);
......@@ -188,6 +203,9 @@ public function testLanguages() {
$config->set('display.default.display_options.filters.langcode.value', array(PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT));
$config->save();
foreach ($this->nodeTitles as $langcode => $titles) {
if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
continue;
}
$this->drupalGet(($langcode == 'en' ? '' : "$langcode/") . 'node');
foreach ($this->nodeTitles as $control_langcode => $control_titles) {
foreach ($control_titles as $title) {
......
......@@ -196,6 +196,7 @@ display:
value:
fr: fr
es: es
und: und
group: 1
exposed: false
expose:
......
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