diff --git a/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php b/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php index 3ccae22..996adc1 100644 --- a/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php +++ b/core/modules/language/lib/Drupal/language/Plugin/Block/LanguageBlock.php @@ -49,6 +49,14 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi $this->languageManager = $language_manager; } + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'block_type' => 'theme', + ); + } /** * {@inheritdoc} @@ -73,6 +81,29 @@ function access(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('JavaScript operations'), + ), + ); + return $form; + } + + /** + * Overrides \Drupal\block\BlockBase::blockSubmit(). + */ + 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,7 +112,6 @@ public function build() { if (isset($links->links)) { $build = array( - '#theme' => 'links__language_block', '#links' => $links->links, '#attributes' => array( 'class' => array( @@ -89,6 +119,17 @@ public function build() { ), ), ); + // Attach some logic. + 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/lib/Drupal/language/Tests/LanguageSwitchingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php index 4613f43..1676f28 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php @@ -60,7 +60,7 @@ function testLanguageBlock() { $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(), @@ -69,7 +69,7 @@ function testLanguageBlock() { '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)) {