LanguageNegotiationAdministrationLanguage.php in Administration Language Negotiation 8
File
src/Plugin/LanguageNegotiation/LanguageNegotiationAdministrationLanguage.php
View source
<?php
declare (strict_types=1);
namespace Drupal\administration_language_negotiation\Plugin\LanguageNegotiation;
use Drupal\administration_language_negotiation\AdministrationLanguageNegotiationConditionManager;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\language\LanguageNegotiationMethodBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class LanguageNegotiationAdministrationLanguage extends LanguageNegotiationMethodBase implements ContainerFactoryPluginInterface {
public const METHOD_ID = 'administration-language-negotiation';
protected $conditionManager;
public function __construct(AdministrationLanguageNegotiationConditionManager $manager, array $configuration, $plugin_id, array $plugin_definition) {
$this->conditionManager = $manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('plugin.manager.administration_language_negotiation_condition'), $configuration, $plugin_id, $plugin_definition);
}
public function getLangcode(Request $request = NULL) {
if ($this->currentUser
->hasPermission('use administration language negotiation')) {
$config = $this->config
->get('administration_language_negotiation.negotiation');
$manager = $this->conditionManager;
foreach ($manager
->getDefinitions() as $def) {
$condition_plugin = $manager
->createInstance($def['id'], $config
->get());
if (!$manager
->execute($condition_plugin)) {
return $this->currentUser
->getPreferredAdminLangcode(FALSE);
}
}
}
return FALSE;
}
}