Skip to content
Snippets Groups Projects

Feature/istwcms 6233 jpconsta create language page settings

3 files
+ 113
31
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -19,6 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class UwMLSetupAddLanguage extends UwMLSetupPluginBase {
use UwMLSetupValidateTrait;
/**
* The language manager.
*
@@ -26,19 +28,11 @@ class UwMLSetupAddLanguage extends UwMLSetupPluginBase {
*/
public $languageManager;
/**
* Config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
public $configFactory;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ContainerInterface $container) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $container);
$this->configFactory = $container->get('config.factory');
$this->languageManager = $container->get('language_manager');
}
@@ -49,29 +43,12 @@ class UwMLSetupAddLanguage extends UwMLSetupPluginBase {
return ['langcode' => $this->configuration['language']];
}
/**
* Get valid lang codes.
*
* @return string[]
* Array of valid lang codes.
*/
public function getValidLanguages() {
return [
'en',
'fr',
'zh-hans',
];
}
/**
* {@inheritdoc}
*/
public function validateData() {
$languages = $this->languageManager->getLanguages();
if (!in_array($this->configuration['language'], $this->getValidLanguages())) {
throw new \Exception('Only the following langcodes are available: ' . implode(', ', $this->getValidLanguages()));
}
elseif (in_array($this->configuration['language'], array_keys($languages))) {
if (in_array($this->configuration['language'], array_keys($languages))) {
return self::EXECUTION_STATUS['SKIP'];
}
return self::EXECUTION_STATUS['EXECUTE'];
@@ -83,11 +60,6 @@ class UwMLSetupAddLanguage extends UwMLSetupPluginBase {
public function processData($data, &$context = []) {
$new_language = ConfigurableLanguage::createFromLangcode($data['langcode']);
$new_language->save();
$this->configFactory->getEditable('system.site')
->set('default_langcode', $data['langcode'])->save();
$this->languageManager->reset();
$context['message'] = $this->batchLabel();
}
}
Loading