Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By plach on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Issue links:
Description:
A field widget and a field formatter were added for the Language field item, so it is no longer needed to explicitly provide a form element to assign a language to an entity in the related add/edit form. It's also no longer necessary for entity type providers to implement hook_entity_extra_field_info()
to describe the Language element.
In fact the related Language entry is automatically made available in the form and view display configuration pages as soon as the Language module is enabled.
Before:
// Entity form
$form['langcode'] = array(
'#title' => t('Language'),
'#type' => 'language_select',
'#default_value' => $node->getUntranslated()->language()->getId(),
'#languages' => LanguageInterface::STATE_ALL,
// Language module may expose or hide this element, see language_form_alter().
'#access' => FALSE,
);
After:
// Entity base field definition
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language'))
->setDescription(t('My custom entity language.'))
->setRevisionable(TRUE)
->setDisplayOptions('view', array(
'type' => 'hidden',
))
->setDisplayOptions('form', array(
'type' => 'language_select',
'weight' => 2,
));
Impacts:
Site builders, administrators, editors
Module developers