diff --git a/core/modules/language/src/Plugin/Block/LanguageBlock.php b/core/modules/language/src/Plugin/Block/LanguageBlock.php index 42d5bf3..0f36abe 100644 --- a/core/modules/language/src/Plugin/Block/LanguageBlock.php +++ b/core/modules/language/src/Plugin/Block/LanguageBlock.php @@ -49,6 +49,14 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->languageManager = $language_manager; } + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'block_type' => 'theme', + ); + } /** * {@inheritdoc} @@ -73,6 +81,29 @@ protected function blockAccess(AccountInterface $account) { /** * {@inheritdoc} */ + public function blockForm($form, &$form_state) { + $form['block_type'] = array( + '#type' => 'radios', + '#title' => t('Display as'), + '#default_value' => $this->configuration['block_type'], + '#options' => array( + 'theme' => t('HTML List'), + 'type' => t('Operations dropdown'), + ), + ); + return $form; + } + + /** + * {@inheritdoc} + */ + public function blockSubmit($form, &$form_state) { + $this->configuration['block_type'] = $form_state['values']['block_type']; + } + + /** + * {@inheritdoc} + */ public function build() { $build = array(); $path = drupal_is_front_page() ? '' : current_path(); @@ -81,15 +112,23 @@ public function build() { if (isset($links->links)) { $build = array( - '#theme' => 'links__language_block', '#links' => $links->links, '#attributes' => array( - 'class' => array( - "language-switcher-{$links->method_id}", - ), + 'class' => array('language-switcher-' . $links->method_id), ), '#set_active_class' => TRUE, ); + + if ($this->configuration['block_type'] == 'theme') { + $build += array( + '#theme' => 'links__language_block', + ); + } + elseif ($this->configuration['block_type'] == 'type') { + $build += array( + '#type' => 'operations', + ); + } } return $build; } diff --git a/core/modules/language/src/Tests/LanguageSwitchingTest.php b/core/modules/language/src/Tests/LanguageSwitchingTest.php index 4a2d245..b6801e7 100644 --- a/core/modules/language/src/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/src/Tests/LanguageSwitchingTest.php @@ -125,7 +125,7 @@ protected function doTestLanguageBlockAnonymous($block_label) { $this->assertText($block_label, 'Language switcher block found.'); // Assert that only the current language is marked as active. - list($language_switcher) = $this->xpath('//div[@id=:id]/div[contains(@class, "content")]', array(':id' => 'block-test-language-block')); + $language_switcher_item = $this->xpath('//div[@id=:id]//li', array(':id' => 'block-test-language-block')); $links = array( 'active' => array(), 'inactive' => array(), @@ -134,7 +134,7 @@ protected function doTestLanguageBlockAnonymous($block_label) { 'active' => array(), 'inactive' => array(), ); - foreach ($language_switcher->ul->li as $link) { + foreach ($language_switcher_item as $link) { $classes = explode(" ", (string) $link['class']); list($langcode) = array_intersect($classes, array('en', 'fr')); if (in_array('active', $classes)) { @@ -156,6 +156,33 @@ protected function doTestLanguageBlockAnonymous($block_label) { } /** + * Functional tests for the operation dropdown display type. + */ + function testLanguageBlockOperations() { + // Enable the language switching block.. + $block = $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array( + 'id' => 'test_language_block', + // Ensure a 2-byte UTF-8 sequence is in the tested output. + 'label' => $this->randomName(8) . '×', + // Display block as operations dropdown. + 'block_type' => 'type', + )); + + // Add language. + $edit = array( + 'predefined_langcode' => 'fr', + ); + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + + // Enable URL language detection and selection. + $edit = array('language_interface[enabled][language-url]' => '1'); + $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + + $operations_dropdown = $this->xpath('//div[@id=:id]//ul[contains(@class, "dropbutton")]', array(':id' => 'block-test-language-block')); + $this->assertTrue($operations_dropdown, 'Language block has been set to operations dropdown display mode.'); + } + + /** * Test active class on links when switching languages. */ function testLanguageLinkActiveClass() {