* - type: The field type.
* - bundles: The bundles in which the field appears.
*
- * @return array
+ * @var array
*/
protected $fieldMap = [];
* flagged as translatable.
*/
protected function buildBaseFieldDefinitions($entity_type_id) {
+ /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
$class = $entity_type->getClass();
+ /** @var string[] $keys */
$keys = array_filter($entity_type->getKeys());
// Fail with an exception for non-fieldable entity types.
}
}
+ // Make sure that revisionable entity types are correctly defined.
+ if ($entity_type->isRevisionable()) {
+ // Disable the BC layer to prevent a recursion, this only needs the
+ // revision_default key that is always set.
+ $field_name = $entity_type->getRevisionMetadataKeys(FALSE)['revision_default'];
+ $base_field_definitions[$field_name] = BaseFieldDefinition::create('boolean')
+ ->setLabel($this->t('Default revision'))
+ ->setDescription($this->t('A flag indicating whether this was a default revision when it was saved.'))
+ ->setStorageRequired(TRUE)
+ ->setInternal(TRUE)
+ ->setTranslatable(FALSE)
+ ->setRevisionable(TRUE);
+ }
+
+ // Make sure that revisionable and translatable entity types are correctly
+ // defined.
+ if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
+ // The 'revision_translation_affected' field should always be defined.
+ // This field has been added unconditionally in Drupal 8.4.0 and it is
+ // overriding any pre-existing definition on purpose so that any
+ // differences are immediately available in the status report.
+ $base_field_definitions[$keys['revision_translation_affected']] = BaseFieldDefinition::create('boolean')
+ ->setLabel($this->t('Revision translation affected'))
+ ->setDescription($this->t('Indicates if the last edit of a translation belongs to current revision.'))
+ ->setReadOnly(TRUE)
+ ->setRevisionable(TRUE)
+ ->setTranslatable(TRUE);
+ }
+
// Assign base field definitions the entity type provider.
$provider = $entity_type->getProvider();
foreach ($base_field_definitions as $definition) {
// Load base field overrides from configuration. These take precedence over
// base field overrides returned above.
- $base_field_override_ids = array_map(function($field_name) use ($entity_type_id, $bundle) {
+ $base_field_override_ids = array_map(function ($field_name) use ($entity_type_id, $bundle) {
return $entity_type_id . '.' . $bundle . '.' . $field_name;
}, array_keys($base_field_definitions));
$base_field_overrides = $this->entityTypeManager->getStorage('base_field_override')->loadMultiple($base_field_override_ids);
}
}
- $this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types']);
+ $this->cacheSet($cid, $this->fieldMap, Cache::PERMANENT, ['entity_types', 'entity_field_info']);
}
}
return $this->fieldMap;