/**
  * @covers ::getName()
  */
 public function testGetName()
 {
     $name = $this->randomMachineName();
     $language_code = $this->randomMachineName(2);
     $language = new Language(array('id' => $language_code, 'name' => $name));
     $this->assertSame($name, $language->getName());
 }
Пример #2
0
 protected function doTestBasicTranslation()
 {
     parent::doTestBasicTranslation();
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     foreach ($this->langcodes as $langcode) {
         if ($entity->hasTranslation($langcode)) {
             $language = new Language(array('id' => $langcode));
             // Request the front page in this language and assert that the right
             // translation shows up in the shortcut list with the right path.
             $this->drupalGet('<front>', array('language' => $language));
             $expected_path = \Drupal::urlGenerator()->generateFromRoute('user.page', array(), array('language' => $language));
             $label = $entity->getTranslation($langcode)->label();
             $elements = $this->xpath('//nav[contains(@class, "toolbar-lining")]/ul[@class="toolbar-menu"]/li/a[contains(@href, :href) and normalize-space(text())=:label]', array(':href' => $expected_path, ':label' => $label));
             $this->assertTrue(!empty($elements), format_string('Translated @language shortcut link @label found.', array('@label' => $label, '@language' => $language->getName())));
         }
     }
 }
Пример #3
0
 /**
  * Tests name getter and setter methods.
  *
  * @covers ::getName()
  * @covers ::setName()
  */
 public function testGetName()
 {
     $name = $this->randomMachineName();
     $this->assertSame($this->language, $this->language->setName($name));
     $this->assertSame($name, $this->language->getName());
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 protected function viewValue(FieldItemInterface $item)
 {
     $settings = $this->getSettings();
     $langcode = $item->value;
     // Do NOT use the languagemanager, since it only uses installed languages.
     // $language_manager = \Drupal::languageManager();
     // $language = $language_manager->getLanguage($langcode); // Does not work for e.g. Danish (da).
     $language = new Language(array('id' => $langcode));
     // Create the markup for this value.
     $markup = array();
     /*
           if (!empty($settings['format']['icon']) && \Drupal::moduleHandler()->moduleExists('languageicons')) {
             // Add a language icon. We might better use languageicons_link_add().
             // @TODO: doesn't work for the Widget, even though hook_options_list says the <img>-tab is allowed.
             $variables = array(
               'language' => $language,  // TODO: what happens if no icon for this language code.
               'title' => $item->getName(), //['name'],
             );
             $markup[] = theme_languageicons_icon($variables);
           }
     */
     if (!empty($settings['format']['iso'])) {
         $markup[] = $langcode;
     }
     if (!empty($settings['format']['name'])) {
         $markup[] = t($language->getName());
     }
     if (!empty($settings['format']['name_native'])) {
         // @todo: Create feature request to add function to D8 core.
         $markup[] = empty($settings['format']['name']) ? $item->getNativeName() : '(' . $item->getNativeName() . ')';
     }
     if (empty($markup)) {
         $markup[] = t($language->getName());
     } else {
         $markup = implode(' ', $markup);
     }
     // The text value has no text format assigned to it, so the user input
     // should equal the output, including newlines.
     return ['#context' => ['value' => $item->value], '#type' => 'processed_text', '#text' => $markup, '#format' => $item->format, '#langcode' => $langcode];
 }