diff --git a/core/modules/language/src/Plugin/Block/LanguageBlock.php b/core/modules/language/src/Plugin/Block/LanguageBlock.php index 7aa9bb8..9e12afb 100644 --- a/core/modules/language/src/Plugin/Block/LanguageBlock.php +++ b/core/modules/language/src/Plugin/Block/LanguageBlock.php @@ -9,6 +9,8 @@ use Drupal\Core\Block\BlockBase; use Drupal\Core\Path\PathMatcherInterface; +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageManager; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -116,4 +118,20 @@ public function getCacheMaxAge() { return 0; } + /** + * {@inheritdoc} + */ + public function blockForm($form, FormStateInterface $form_state) { + $form = parent::blockForm($form, $form_state); + $path = drupal_is_front_page() ? '' : Url::fromRoute(''); + list(, $type) = explode(':', $this->getPluginId()); + $links = $this->languageManager->getLanguageSwitchLinks($type, $path); + // Warn the user that if there are no links to show, the block won't appear. + if (empty($links)) { + drupal_set_message($this->t('You do not have any language detection method enabled that provides URL based detection. The language switcher module will not be shown.'), 'warning'); + } + + return $form; + } + }