diff --git a/core/modules/language/language.views.inc b/core/modules/language/language.views.inc new file mode 100644 index 0000000..7521d52 --- /dev/null +++ b/core/modules/language/language.views.inc @@ -0,0 +1,91 @@ + 'langcode', + 'title' => t('Language'), + 'help' => t('A language used in drupal.'), + ); + + $data['language']['langcode'] = array( + 'title' => t('Language code'), + 'help' => t("Language code, e.g. 'de' or 'en-US'."), + 'field' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string' + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['language']['name'] = array( + 'title' => t('Language name'), + 'help' => t("Language name, e.g. 'German' or 'English'."), + 'field' => array( + 'id' => 'standard', + ), + 'filter' => array( + 'id' => 'string' + ), + 'argument' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['language']['direction'] = array( + 'title' => t('Direction'), + 'help' => t('Direction of language (Left-to-Right = 0, Right-to-Left = 1).'), + 'field' => array( + 'id' => 'numeric', + ), + 'filter' => array( + 'id' => 'numeric' + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['language']['weight'] = array( + 'title' => t('Weight'), + 'help' => t('Weight, used in lists of languages.'), + 'field' => array( + 'id' => 'numeric', + ), + 'filter' => array( + 'id' => 'numeric' + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + return $data; +} diff --git a/core/modules/language/lib/Drupal/language/Plugin/views/argument/LanguageArgument.php b/core/modules/language/lib/Drupal/language/Plugin/views/argument/LanguageArgument.php new file mode 100644 index 0000000..33a461e --- /dev/null +++ b/core/modules/language/lib/Drupal/language/Plugin/views/argument/LanguageArgument.php @@ -0,0 +1,59 @@ +language($data->{$this->name_alias}); + } + + /** + * Overrides \Drupal\views\Plugin\views\argument\ArgumentPluginBase::summary_name(). + * + * Gets the user friendly version of the language name for display as a + * title placeholder. + */ + function title() { + return $this->language($this->argument); + } + + /** + * Returns the language name for a given langcode. + * + * @param string $langcode + * The language code. + * + * @return string + * The translated name for the language, or "Unknown language" if the + * language was not found. + */ + function language($langcode) { + $languages = views_language_list(); + return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language'); + } + +} diff --git a/core/modules/language/lib/Drupal/language/Plugin/views/field/LanguageField.php b/core/modules/language/lib/Drupal/language/Plugin/views/field/LanguageField.php new file mode 100644 index 0000000..54725f0 --- /dev/null +++ b/core/modules/language/lib/Drupal/language/Plugin/views/field/LanguageField.php @@ -0,0 +1,50 @@ + FALSE, 'bool' => TRUE); + + return $options; + } + + public function buildOptionsForm(&$form, &$form_state) { + parent::buildOptionsForm($form, $form_state); + $form['native_language'] = array( + '#title' => t('Native language'), + '#type' => 'checkbox', + '#default_value' => $this->options['native_language'], + '#description' => t('If enabled, the native name of the language will be displayed'), + ); + } + + function render($values) { + // @todo: Drupal Core dropped native language until config translation is + // ready, see http://drupal.org/node/1616594. + $value = $this->get_value($values); + $language = language_load($value); + return $language ? $language->name : ''; + } + +} diff --git a/core/modules/language/lib/Drupal/language/Plugin/views/filter/LanguageFilter.php b/core/modules/language/lib/Drupal/language/Plugin/views/filter/LanguageFilter.php new file mode 100644 index 0000000..59a6764 --- /dev/null +++ b/core/modules/language/lib/Drupal/language/Plugin/views/filter/LanguageFilter.php @@ -0,0 +1,37 @@ +value_options)) { + $this->value_title = t('Language'); + $languages = array( + '***CURRENT_LANGUAGE***' => t("Current user's language"), + '***DEFAULT_LANGUAGE***' => t("Default site language"), + ); + $languages = array_merge($languages, views_language_list()); + $this->value_options = $languages; + } + } + +} diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index cf68a49..764b0ce 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -1225,7 +1225,7 @@ public function optionsSummary(&$categories, &$options) { if ($this->usesLinkDisplay()) { $display_id = $this->getLinkDisplay(); - $link_display = empty($this->view->display[$display_id]) ? t('None') : check_plain($this->view->display[$display_id]['display_title']); + $link_display = empty($this->view->storage->display[$display_id]) ? t('None') : check_plain($this->view->storage->display[$display_id]['display_title']); $link_display = $this->getOption('link_display') == 'custom_url' ? t('Custom URL') : $link_display; $options['link_display'] = array( 'category' => 'other', @@ -1537,7 +1537,6 @@ public function buildOptionsForm(&$form, &$form_state) { $languages = array( '***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), - LANGUAGE_NOT_SPECIFIED => t('Language neutral'), ); $languages = array_merge($languages, views_language_list()); diff --git a/core/modules/views/lib/Drupal/views/Tests/Language/ArgumentLanguageTest.php b/core/modules/views/lib/Drupal/views/Tests/Language/ArgumentLanguageTest.php new file mode 100644 index 0000000..13cb149 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Language/ArgumentLanguageTest.php @@ -0,0 +1,50 @@ + 'Argument: Language', + 'description' => 'Tests the argument language handler.', + 'group' => 'Views Handlers' + ); + } + + /** + * Tests the language argument. + */ + public function testArgument() { + foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) { + $view = $this->getView(); + $view->displayHandlers['default']->overrideOption('arguments', array( + 'langcode' => array( + 'id' => 'langcode', + 'table' => 'views_test_data', + 'field' => 'langcode', + ), + )); + $this->executeView($view, array($langcode)); + + $expected = array(array( + 'name' => $name, + )); + $this->assertIdenticalResultset($view, $expected, array('views_test_data_name' => 'name')); + $view->destroy(); + } + } + +} diff --git a/core/modules/views/lib/Drupal/views/Tests/Language/FieldLanguageTest.php b/core/modules/views/lib/Drupal/views/Tests/Language/FieldLanguageTest.php new file mode 100644 index 0000000..0fbe8d4 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Language/FieldLanguageTest.php @@ -0,0 +1,45 @@ + 'Field: Language', + 'description' => 'Tests the field language handler.', + 'group' => 'Views Handlers', + ); + } + + /** + * Tests the language field. + */ + public function testField() { + $view = $this->getView(); + $view->displayHandlers['default']->overrideOption('fields', array( + 'langcode' => array( + 'id' => 'langcode', + 'table' => 'views_test_data', + 'field' => 'langcode', + ), + )); + $this->executeView($view); + + $this->assertEqual($view->field['langcode']->advanced_render($view->result[0]), 'English'); + $this->assertEqual($view->field['langcode']->advanced_render($view->result[1]), 'Lolspeak'); + } + +} diff --git a/core/modules/views/lib/Drupal/views/Tests/Language/FilterLanguageTest.php b/core/modules/views/lib/Drupal/views/Tests/Language/FilterLanguageTest.php new file mode 100644 index 0000000..a2c99cc --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Language/FilterLanguageTest.php @@ -0,0 +1,51 @@ + 'Filter: Language', + 'description' => 'Tests the filter language handler.', + 'group' => 'Views Handlers' + ); + } + + /** + * Tests the language filter. + */ + public function testFilter() { + foreach (array('en' => 'John', 'xx-lolspeak' => 'George') as $langcode => $name) { + $view = $this->getView(); + $view->displayHandlers['default']->overrideOption('filters', array( + 'langcode' => array( + 'id' => 'langcode', + 'table' => 'views_test_data', + 'field' => 'langcode', + 'value' => array($langcode), + ), + )); + $this->executeView($view); + + $expected = array(array( + 'name' => $name, + )); + $this->assertIdenticalResultset($view, $expected, array('views_test_data_name' => 'name')); + $view->destroy(); + } + } + +} diff --git a/core/modules/views/lib/Drupal/views/Tests/Language/LanguageTestBase.php b/core/modules/views/lib/Drupal/views/Tests/Language/LanguageTestBase.php new file mode 100644 index 0000000..94d5a29 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Language/LanguageTestBase.php @@ -0,0 +1,86 @@ +enableViewsTestModule(); + + // Create another language beside English. + $language = new Language(array('langcode' => 'xx-lolspeak', 'name' => 'Lolspeak')); + language_save($language); + } + + /** + * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition(). + */ + protected function schemaDefinition() { + $schema = parent::schemaDefinition(); + $schema['views_test_data']['fields']['langcode'] = array( + 'description' => 'The {language}.langcode of this beatle.', + 'type' => 'varchar', + 'length' => 12, + 'default' => '', + ); + + return $schema; + } + + /** + * Overrides \Drupal\views\Tests\ViewTestBase::schemaDefinition(). + */ + protected function viewsData() { + $data = parent::viewsData(); + $data['views_test_data']['langcode'] = array( + 'title' => t('Langcode'), + 'help' => t('Langcode'), + 'field' => array( + 'id' => 'language', + ), + 'argument' => array( + 'id' => 'language', + ), + 'filter' => array( + 'id' => 'language', + ), + ); + + return $data; + } + + /** + * Overrides \Drupal\views\Tests\ViewTestBase::dataSet(). + */ + protected function dataSet() { + $data = parent::dataSet(); + $data[0]['langcode'] = 'en'; + $data[1]['langcode'] = 'xx-lolspeak'; + $data[2]['langcode'] = ''; + $data[3]['langcode'] = ''; + $data[4]['langcode'] = ''; + + return $data; + } + +} diff --git a/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php index 0fd4bc3..de1d78a 100644 --- a/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/UI/DisplayTest.php @@ -55,7 +55,8 @@ public function testRemoveDisplay() { // Delete the page, so we can test the undo process. $this->drupalPost($path_prefix . '/page_1', array(), 'delete Page'); $this->assertFieldById('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete', 'undo delete of Page', 'Make sure there a undo button on the page display after deleting.'); - $this->assertTrue($this->xpath('//a[contains(@class, :class)]', array(':class' => 'views-display-deleted-link')), 'Make sure the display link is marked as to be deleted.'); + $element = $this->xpath('//a[contains(@href, :href) and contains(@class, :class)]', array(':href' => $path_prefix . '/page_1', ':class' => 'views-display-deleted-link')); + $this->assertTrue(!empty($element), 'Make sure the display link is marked as to be deleted.'); // Undo the deleting of the display. $this->drupalPost($path_prefix . '/page_1', array(), 'undo delete of Page'); @@ -128,7 +129,7 @@ public function testReorderDisplay() { */ public function testDefaultDisplay() { $this->drupalGet('admin/structure/views/view/test_display'); - $elements = $this->xpath('//*[@id="views-page-display-title"]'); + $elements = $this->xpath('//*[@id="views-page-1-display-title"]'); $this->assertEqual(count($elements), 1, 'The page display is loaded as the default display.'); } @@ -182,4 +183,26 @@ public function testDisplayPluginsAlter() { } } + /** + * Tests the link-display setting. + */ + public function testLinkDisplay() { + // Test setting the link display in the UI form. + $path = 'admin/structure/views/view/test_display/edit/block_1'; + $link_display_path = 'admin/structure/views/nojs/display/test_display/block_1/link_display'; + $this->drupalPost($link_display_path, array('link_display' => 'page_1'), t('Apply')); + // The form redirects to the master display. + $this->drupalGet($path); + + $result = $this->xpath("//a[contains(@href, :path)]", array(':path' => $link_display_path)); + $this->assertEqual($result[0], 'Page', 'Make sure that the link option summary shows the right linked display.'); + + $link_display_path = 'admin/structure/views/nojs/display/test_display/block_1/link_display'; + $this->drupalPost($link_display_path, array('link_display' => 'custom_url'), t('Apply')); + // The form redirects to the master display. + $this->drupalGet($path); + + $this->assertLink(t('Custom URL'), 0, 'The link option has custom url as summary.'); + } + } diff --git a/core/modules/views/tests/views_test_config/config/views.view.test_display.yml b/core/modules/views/tests/views_test_config/config/views.view.test_display.yml index 5c44bb2..d18b24f 100644 --- a/core/modules/views/tests/views_test_config/config/views.view.test_display.yml +++ b/core/modules/views/tests/views_test_config/config/views.view.test_display.yml @@ -4,7 +4,7 @@ core: '8' description: '' disabled: '1' display: - block: + block_1: display_options: defaults: pager: '0' @@ -30,7 +30,7 @@ display: style_plugin: default display_plugin: block display_title: Block - id: block + id: block_1 position: '2' default: display_options: @@ -75,12 +75,12 @@ display: display_title: Master id: default position: '0' - page: + page_1: display_options: path: test-display display_plugin: page display_title: Page - id: page + id: page_1 position: '1' human_name: '' name: test_display diff --git a/core/modules/views/views.module b/core/modules/views/views.module index c29136a..b74f8ad 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -887,26 +887,24 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable } /** - * Returns an array of language names. + * Prepares a list of language names. * - * This is a one to one copy of locale_language_list because we can't rely on enabled locale module. + * This is a wrapper around language_list to return a plain key value array. * - * @param $field - * 'name' => names in current language, localized - * 'native' => native names - * @param $all - * Boolean to return all languages or only enabled ones + * @param string $field + * The field of the language object which should be used as the value of the + * array. + * @param int $flags + * (optional) Specifies the state of the languages that have to be returned. + * It can be: LANGUAGE_CONFIGURABLE, LANGUAGE_LOCKED, LANGUAGE_ALL. + * + * @return array + * An array of language names (or $field) keyed by the langcode. * * @see locale_language_list() - * @todo Figure out whether we need this with language module. */ -function views_language_list($field = 'name', $all = FALSE) { - if ($all) { - $languages = language_list(); - } - else { - $languages = language_list(); - } +function views_language_list($field = 'name', $flags = LANGUAGE_ALL) { + $languages = language_list($flags); $list = array(); foreach ($languages as $language) { $list[$language->langcode] = ($field == 'name') ? t($language->name) : $language->$field;