/**
  * {@inheritDoc}
  */
 public function populate(EnvironmentInterface $environment)
 {
     if (!$environment->getSessionStorage()) {
         $environment->setSessionStorage(new SessionStorage('DC_GENERAL_' . strtoupper($environment->getDataDefinition()->getName())));
     }
     if (!$environment->getInputProvider()) {
         $environment->setInputProvider(new InputProvider());
     }
     if (!$environment->getClipboard()) {
         $environment->setClipboard(new Clipboard());
     }
     if (!$environment->getBaseConfigRegistry()) {
         $baseConfigRegistry = new BaseConfigRegistry();
         $baseConfigRegistry->setEnvironment($environment);
         $environment->setBaseConfigRegistry($baseConfigRegistry);
     }
     $this->populateController($environment);
 }
Example #2
0
 /**
  * Check if the language has been switched.
  *
  * If so, the value in the session will be updated and the page reloaded.
  *
  * @param EnvironmentInterface $environment The environment.
  *
  * @return void
  */
 private function checkLanguageSubmit($environment)
 {
     $sessionStorage = $environment->getSessionStorage();
     $inputProvider = $environment->getInputProvider();
     if ($inputProvider->getValue('FORM_SUBMIT') !== 'language_switch') {
         return;
     }
     $modelId = $inputProvider->getParameter('id') && $inputProvider->getParameter('id') ? IdSerializer::fromSerialized($inputProvider->getParameter('id'))->getId() : null;
     $languages = $environment->getController()->getSupportedLanguages($modelId);
     $providerName = $environment->getDataDefinition()->getName();
     // Get/Check the new language.
     if ($inputProvider->hasValue('language') && array_key_exists($inputProvider->getValue('language'), $languages)) {
         $session['ml_support'][$providerName][$modelId] = $inputProvider->getValue('language');
         $sessionStorage->set('dc_general', $session);
     }
     $environment->getEventDispatcher()->dispatch(ContaoEvents::CONTROLLER_RELOAD, new ReloadEvent());
 }