22
33namespace Drupal \graphql \EventSubscriber ;
44
5+ use Drupal \Core \Extension \ModuleHandlerInterface ;
56use Drupal \Core \Language \LanguageManagerInterface ;
67use Drupal \Core \Session \AccountInterface ;
78use Drupal \Core \StringTranslation \Translator \TranslatorInterface ;
89use Drupal \graphql \Event \OperationEvent ;
910use Drupal \graphql \Plugin \LanguageNegotiation \OperationLanguageNegotiation ;
10- use Drupal \language \ConfigurableLanguageManagerInterface ;
1111use Drupal \language \LanguageNegotiatorInterface ;
1212use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
1313
1414class OperationSubscriber implements EventSubscriberInterface {
1515
1616 use CurrentLanguageResetTrait;
1717
18+ /**
19+ * The module handler service.
20+ *
21+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
22+ */
23+ protected $ moduleHandler ;
24+
1825 /**
1926 * Constructs a OperationSubscriber object.
2027 *
28+ * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
2129 * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
2230 * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator
2331 * @param \Drupal\Core\Session\AccountInterface $currentUser
2432 * @param \Drupal\language\LanguageNegotiatorInterface $languageNegotiator
2533 */
26- public function __construct (LanguageManagerInterface $ languageManager , TranslatorInterface $ translator , AccountInterface $ currentUser , LanguageNegotiatorInterface $ languageNegotiator = NULL ) {
34+ public function __construct (ModuleHandlerInterface $ moduleHandler , LanguageManagerInterface $ languageManager , TranslatorInterface $ translator , AccountInterface $ currentUser , LanguageNegotiatorInterface $ languageNegotiator = NULL ) {
35+ $ this ->moduleHandler = $ moduleHandler ;
2736 $ this ->languageManager = $ languageManager ;
2837 $ this ->translator = $ translator ;
2938 $ this ->currentUser = $ currentUser ;
@@ -37,7 +46,7 @@ public function __construct(LanguageManagerInterface $languageManager, Translato
3746 * The kernel event object.
3847 */
3948 public function onBeforeOperation (OperationEvent $ event ) {
40- if (!empty ($ this ->languageNegotiator )) {
49+ if ($ this -> moduleHandler -> moduleExists ( ' language ' ) && !empty ($ this ->languageNegotiator )) {
4150 OperationLanguageNegotiation::setContext ($ event ->getContext ());
4251 }
4352
@@ -51,7 +60,7 @@ public function onBeforeOperation(OperationEvent $event) {
5160 * The kernel event object.
5261 */
5362 public function onAfterOperation (OperationEvent $ event ) {
54- if (!empty ($ this ->languageNegotiator )) {
63+ if ($ this -> moduleHandler -> moduleExists ( ' language ' ) && !empty ($ this ->languageNegotiator )) {
5564 OperationLanguageNegotiation::setContext ($ event ->getContext ());
5665 }
5766
0 commit comments