Skip to content
Snippets Groups Projects
Commit b632fd73 authored by Dmitry Kiselev's avatar Dmitry Kiselev
Browse files

Issue #3431537 by poker10, sheshsharma, manishvaity, sneha_surve, kala4ek:...

Issue #3431537 by poker10, sheshsharma, manishvaity, sneha_surve, kala4ek: Automated Drupal 11 compatibility fixes for lang_dropdown
parent 0ab1b0b5
Branches
Tags 8.x-2.2
No related merge requests found
......@@ -2,7 +2,7 @@ name: 'Language Switcher Dropdown'
type: module
description: 'Provides a dropdown select to switch between available languages.'
package: Multilingual
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^9.3 || ^10 || ^11
dependencies:
- drupal:language
configure: block.admin_display
......@@ -4,10 +4,10 @@ namespace Drupal\lang_dropdown\Plugin\Block;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Asset\LibraryDiscoveryCollector;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Asset\LibraryDiscovery;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -20,6 +20,7 @@ use Drupal\lang_dropdown\LanguageDropdownConstants;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\TypedData\TranslationStatusInterface;
use Drupal\user\Entity\Role;
/**
* Provides a 'Language dropdown switcher' block.
......@@ -57,9 +58,9 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
/**
* The library discovery service.
*
* @var \Drupal\Core\Asset\LibraryDiscovery
* @var \Drupal\Core\Asset\LibraryDiscoveryCollector
*/
protected $libraryDiscovery;
protected $libraryDiscoveryCollector;
/**
* The current user account.
......@@ -90,19 +91,19 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
* The path matcher.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Asset\LibraryDiscovery $library_discovery
* @param \Drupal\Core\Asset\LibraryDiscoveryCollector $library_discovery_collector
* The library discovery service.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user account.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager, PathMatcherInterface $path_matcher, ModuleHandlerInterface $module_handler, LibraryDiscovery $library_discovery, AccountProxyInterface $current_user, FormBuilderInterface $form_builder) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager, PathMatcherInterface $path_matcher, ModuleHandlerInterface $module_handler, LibraryDiscoveryCollector $library_discovery_collector, AccountProxyInterface $current_user, FormBuilderInterface $form_builder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->languageManager = $language_manager;
$this->pathMatcher = $path_matcher;
$this->moduleHandler = $module_handler;
$this->libraryDiscovery = $library_discovery;
$this->libraryDiscoveryCollector = $library_discovery_collector;
$this->currentUser = $current_user;
$this->formBuilder = $form_builder;
}
......@@ -253,7 +254,7 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
$form['lang_dropdown']['msdropdown']['#description'] = $this->t('This looks better with <a href=":link">language icons</a> module.', [':link' => LanguageDropdownConstants::LANGDROPDOWN_LANGUAGEICONS_MOD_URL]);
}
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'ms-dropdown');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'ms-dropdown');
if (!empty($library)) {
$num_rows = [
2,
......@@ -402,7 +403,7 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
],
];
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'chosen');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'chosen');
if (!empty($library) && !$this->moduleHandler->moduleExists('chosen')) {
$form['lang_dropdown']['chosen']['disable_search'] = [
'#type' => 'checkbox',
......@@ -451,7 +452,7 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
],
];
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'ddslick');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'ddslick');
if (!empty($library)) {
$form['lang_dropdown']['ddslick']['ddslick_height'] = [
'#type' => 'number',
......@@ -555,7 +556,7 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
];
$languages = $this->languageManager->getLanguages();
$roles = user_roles();
$roles = Role::loadMultiple();
$role_names = [];
$role_languages = [];
......@@ -616,21 +617,21 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
$widget = $form_state->getValue('lang_dropdown')['widget'];
switch ($widget) {
case LanguageDropdownConstants::LANGDROPDOWN_MSDROPDOWN:
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'ms-dropdown');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'ms-dropdown');
if (empty($library) || (isset($library['js']) && !file_exists($library['js'][0]['data']))) {
$form_state->setErrorByName('settings', $this->t('You can\'t use <a href=":link">Marghoob Suleman Dropdown</a> output. You don\'t have the library installed.', [':link' => LanguageDropdownConstants::LANGDROPDOWN_MSDROPDOWN_URL]));
}
break;
case LanguageDropdownConstants::LANGDROPDOWN_CHOSEN:
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'chosen');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'chosen');
if (empty($library) || (isset($library['js']) && !file_exists($library['js'][0]['data']))) {
$form_state->setErrorByName('settings', $this->t('You can\'t use <a href=":link">Chosen</a> output. You don\'t have the library installed.', [':link' => LanguageDropdownConstants::LANGDROPDOWN_CHOSEN_MOD_URL]));
}
break;
case LanguageDropdownConstants::LANGDROPDOWN_DDSLICK:
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'ddslick');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'ddslick');
if (empty($library) || (isset($library['js']) && !file_exists($library['js'][0]['data']))) {
$form_state->setErrorByName('settings', $this->t('You can\'t use <a href=":link">ddSlick</a> output. You don\'t have the library installed.', [':link' => LanguageDropdownConstants::LANGDROPDOWN_DDSLICK_WEB_URL]));
}
......@@ -700,15 +701,15 @@ class LanguageDropdownBlock extends BlockBase implements ContainerFactoryPluginI
$library = [];
switch ($this->configuration['widget']) {
case LanguageDropdownConstants::LANGDROPDOWN_MSDROPDOWN:
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'ms-dropdown');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'ms-dropdown');
break;
case LanguageDropdownConstants::LANGDROPDOWN_CHOSEN:
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'chosen');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'chosen');
break;
case LanguageDropdownConstants::LANGDROPDOWN_DDSLICK:
$library = $this->libraryDiscovery->getLibraryByName('lang_dropdown', 'ddslick');
$library = $this->libraryDiscoveryCollector->getLibraryByName('lang_dropdown', 'ddslick');
break;
}
......
......@@ -20,7 +20,7 @@ class LanguageSwitchingTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
protected static $modules = [
'block',
'language',
'lang_dropdown',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment