getTranslatedMessage example

      // submit, in which case the user has bigger problems.       try {
        // Install the given modules.         $this->moduleInstaller->install(array_keys($this->modules['install']));
      }
      catch (PreExistingConfigException $e) {
        $this->messenger()->addError($this->modulesFailToEnableMessage($this->modules, $e));
        return;
      }
      catch (UnmetDependenciesException $e) {
        $this->messenger()->addError(
          $e->getTranslatedMessage($this->getStringTranslation()$this->modules['install'][$e->getExtension()])
        );
        return;
      }

      // Unset the messenger to make sure that we'll get the service from the       // new container.       $this->messenger = NULL;
      $this->messenger()
        ->addStatus($this->modulesEnabledConfirmationMessage($this->modules['install']));
    }

    
$this->formatPlural(
            count($config_objects),
            'Unable to install @extension, %config_names already exists in active configuration.',
            'Unable to install @extension, %config_names already exist in active configuration.',
            [
              '%config_names' => implode(', ', $config_objects),
              '@extension' => $theme,
            ])
        );
      }
      catch (UnmetDependenciesException $e) {
        $this->messenger()->addError($e->getTranslatedMessage($this->getStringTranslation()$theme));
      }
      catch (MissingDependencyException $e) {
        $this->messenger()->addError($this->t('Unable to install @theme due to missing module dependencies.', ['@theme' => $theme]));
      }

      return $this->redirect('system.themes_page');
    }

    throw new AccessDeniedHttpException();
  }

  
try {
        $this->moduleInstaller->install(array_keys($modules['install']));
        $this->messenger()
          ->addStatus($this->modulesEnabledConfirmationMessage($modules['install']));
      }
      catch (PreExistingConfigException $e) {
        $this->messenger()->addError($this->modulesFailToEnableMessage($modules$e));
        return;
      }
      catch (UnmetDependenciesException $e) {
        $this->messenger()->addError(
          $e->getTranslatedMessage($this->getStringTranslation()$modules['install'][$e->getExtension()])
        );
        return;
      }
    }
  }

}
$this->formatPlural(
          count($config_objects),
          'Unable to install @extension, %config_names already exists in active configuration.',
          'Unable to install @extension, %config_names already exist in active configuration.',
          [
            '%config_names' => implode(', ', $config_objects),
            '@extension' => $theme,
          ])
      );
    }
    catch (UnmetDependenciesException $e) {
      $this->messenger()->addError($e->getTranslatedMessage($this->getStringTranslation()$theme));
    }
    $form_state->setRedirectUrl($this->getCancelUrl());
  }

}
Home | Imprint | This part of the site doesn't use cookies.