Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EWPP-606: Introduce category setting to language config entity. #114

Merged
merged 4 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/install/language.entity.bg.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: bg
label: Bulgarian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.cs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: cs
label: Czech
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.da.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: da
label: Danish
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.de.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: de
label: German
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.el.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: el
label: Greek
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.es.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: es
label: Spanish
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.et.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: et
label: Estonian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.fi.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: fi
label: Finnish
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.fr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: fr
label: French
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.ga.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: ga
label: Irish
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.hr.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: hr
label: Croatian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.hu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: hu
label: Hungarian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.it.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: it
label: Italian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.lt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: lt
label: Lithuanian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.lv.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: lv
label: Latvian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.mt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: mt
label: Maltese
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.nl.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: nl
label: Dutch
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.pl.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: pl
label: Polish
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.pt-pt.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: pt-pt
label: Portuguese
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.ro.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: ro
label: Romanian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.sk.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: sk
label: Slovak
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.sl.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: sl
label: Slovenian
direction: ltr
Expand Down
3 changes: 3 additions & 0 deletions config/install/language.entity.sv.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
langcode: en
status: true
dependencies: { }
third_party_settings:
oe_multilingual:
category: eu
id: sv
label: Swedish
direction: ltr
Expand Down
7 changes: 7 additions & 0 deletions config/schema/oe_multilingual.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language.entity.*.third_party.oe_multilingual:
type: mapping
label: 'Language category'
mapping:
category:
type: string
label: 'The category of the language.'
7 changes: 7 additions & 0 deletions oe_multilingual.install
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ function oe_multilingual_install() {
return;
}

// Set EU category for the English language.
\Drupal::entityTypeManager()
->getStorage('configurable_language')
->load('en')
->setThirdPartySetting('oe_multilingual', 'category', 'eu')
->save();

// Set up the weight of the English language.
\Drupal::configFactory()
->getEditable('language.entity.en')
Expand Down
42 changes: 42 additions & 0 deletions oe_multilingual.module
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;

/**
* Implements hook_language_switch_links_alter().
Expand Down Expand Up @@ -195,3 +197,43 @@ function oe_multilingual_page_header_pre_render(array $build): array {
function oe_multilingual_locale_translation_projects_alter(&$projects) {
$projects['oe_multilingual']['info']['interface translation server pattern'] = drupal_get_path('module', 'oe_multilingual') . '/translations/%project-%language.po';
}

/**
* Implements hook_form_FORM_ID_alter().
*
* Add a category selection to language entity form.
*/
function oe_multilingual_form_language_admin_edit_form_alter(&$form, FormStateInterface $form_state): void {
/** @var \Drupal\language\Entity\ConfigurableLanguage $language */
$language = $form_state->getFormObject()->getEntity();
$form['category'] = [
'#type' => 'select',
'#title' => t('Category'),
'#required' => TRUE,
'#options' => [
'eu' => t('EU'),
'non_eu' => t('Non-EU'),
],
'#default_value' => $language->getThirdPartySetting('oe_multilingual', 'category'),
];

$form['#entity_builders'][] = 'oe_multilingual_form_language_edit_form_builder';
}

/**
* Entity form builder for the language edit form.
*
* Saves the language category into the language settings.
*
* @param string $entity_type
* The name of the entity type.
* @param \Drupal\language\Entity\ConfigurableLanguage $language
* The language entity.
* @param array $form
* The form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
function oe_multilingual_form_language_edit_form_builder(string $entity_type, ConfigurableLanguage $language, array &$form, FormStateInterface $form_state): void {
$language->setThirdPartySetting('oe_multilingual', 'category', $form_state->getValue('category'));
}
38 changes: 38 additions & 0 deletions oe_multilingual.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,41 @@
function oe_multilingual_post_update_00001_invalidate_containers_cache(): void {
\Drupal::service('kernel')->invalidateContainer();
}

/**
* Apply EU category to EU languages.
*/
function oe_multilingual_post_update_00002(): void {
$eu_languages = [
'en',
'sv',
'lv',
'pl',
'lt',
'da',
'fr',
'hr',
'sl',
'ro',
'es',
'cs',
'nl',
'ga',
'mt',
'pt-pt',
'it',
'fi',
'el',
'hu',
'et',
'de',
'bg',
'sk',
];
$languages = \Drupal::entityTypeManager()->getStorage('configurable_language')->loadMultiple($eu_languages);
foreach ($languages as $language) {
/** @var \Drupal\language\Entity\ConfigurableLanguage $language */
$language->setThirdPartySetting('oe_multilingual', 'category', 'eu');
$language->save();
}
}
Loading