- 🇩🇪Germany sascha_meissner Planet earth
In case anyone might find this useful, this code will remove the edit-langcode element from ContentEntityForms if there are already translations created to prevent the error "Can't change the default langauge"
/** * Implements hook_form_alter(). */ function yourmodule_form_alter(&$form, FormStateInterface $form_state, $form_id) { $form_object = $form_state->getFormObject(); if ($form_object instanceof ContentEntityFormInterface) { // Prevent switching languages on already translated content. // @see \Drupal\content_translation\ContentTranslationHandler::entityFormAlter. $entity = $form_object->getEntity(); if ($entity->isTranslatable() && count($entity->getTranslationLanguages()) > 1) { // Translations exist, prevent language switching. $langcode_key = $entity->getEntityType()->getKey('langcode'); $form[$langcode_key]['widget']['#access'] = FALSE; } } }
- Status changed to Postponed
over 1 year ago 12:12pm 14 July 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
But additionally we need constraints that ensure that there is always a valid default language.
— @mkalkbrenner in #3, >8 years ago.
This is now within reach: ✨ Add a `langcode` data type to config schema Fixed is RTBC, and then we'll still need to do the work here to actually run validation constraints 😊
- 🇨🇭Switzerland berdir Switzerland
@Wim: This is about content entities and the boolean default_langcode flag. (ensuring that exactly one translation has this flag). That has nothing to do with langcode validation in config entities.
- Status changed to Active
over 1 year ago 12:36pm 14 July 2023 - 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Mea culpa — I thought it was about a
default_langcode
setting in someField(Storage)Config
. 🙈That being said … exactly the same validation approach will be usable here AFAICT? 😊 That'd be:
constraints: NotNull: [] Choice: callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'
That's also why I didn't dig very deep into this issue, because that alone landing in core in another issue would be sufficient to make this issue more actionable?
- 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
✨ Add a `langcode` data type to config schema Fixed landed. Per #43, AFAICT that should still help this issue! 😊
- First commit to issue fork.
- Merge request !7331#2443991 Allow default_langcode field value to be changed → (Open) created by Taran2L