In 8.4.x the revision_translation_affected flag has become required for any revisionable and translatable entity type, and it is now provided automatically by the entity field manager.
The revision_translation_affected field indicates which translations were changed for every revision. This information is now required to ensure data integrity for translation of revisions in different publishing states.
If an entity type defined by a contributed module or in custom code already defines a field with the same name, there are two options:
- If the field semantics is the same, just remove the definition from your base field definitions. If for some reason the legacy definition differs from the core one, add an update function to update the installed definition:
/** * Update the "revision_translation_affected" field storage definition. */ function my_module_update_8401() { \Drupal::entityTypeManager() ->clearCachedDefinitions(); /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */ $entity_field_manager = \Drupal::service('entity_field.manager'); $entity_field_manager ->clearCachedFieldDefinitions(); $storage_definitions = $entity_field_manager ->getFieldStorageDefinitions('my_entity_type_id'); \Drupal::entityDefinitionUpdateManager() ->updateFieldStorageDefinition($storage_definitions['revision_translation_affected']); }If the differences are meaningful and do not break core's assumptions, in which case you should skip to the following scenario, you can use
hook_entity_base_field_info_alter()to restore them. In this case you will not need an update function:/** * Implements hook_entity_base_field_info_alter(). */ function my_module_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) { if ($entity_type->id() == 'my_entity_type_id') { $fields['revision_translation_affected']->setDefaultValue(FALSE); // My custom alteration } } - Otherwise, if the semantics is completely different, provide a different name for the
revision_translation_affectedflag via the corresponding entity key and add an update function to install the new definition:
/** * Implements hook_entity_type_alter(). */ function my_module_entity_type_alter(array &$entity_types) { /** @var EntityTypeInterface $entity_type */ $entity_type = $entity_types['my_entity_type_id']; $keys = $entity_type->getKeys(); // Actually this can be done directly in the entity type definition. $keys['revision_translation_affected'] = 'rta_core'; $entity_type->set('entity_keys', $keys); } /** * Add the "rta_core" field to the "my_entity_type_id" entity type. */ function my_module_update_8401() { drupal_flush_all_caches(); $entity_type_id = 'my_entity_type_id'; $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); $field_name = $entity_type->getKey('revision_translation_affected'); $storage_definition = BaseFieldDefinition::create('boolean') ->setLabel(t('Revision translation affected')) ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.')) ->setReadOnly(TRUE) ->setRevisionable(TRUE) ->setTranslatable(TRUE) ->setInitialValue(TRUE); \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition($field_name, $entity_type_id, 'my_module', $storage_definition); }