comparison core/lib/Drupal/Core/Entity/EntityFieldManager.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
188 * @throws \LogicException 188 * @throws \LogicException
189 * Thrown if a config entity type is given or if one of the entity keys is 189 * Thrown if a config entity type is given or if one of the entity keys is
190 * flagged as translatable. 190 * flagged as translatable.
191 */ 191 */
192 protected function buildBaseFieldDefinitions($entity_type_id) { 192 protected function buildBaseFieldDefinitions($entity_type_id) {
193 /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
193 $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); 194 $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
194 $class = $entity_type->getClass(); 195 $class = $entity_type->getClass();
196 /** @var string[] $keys */
195 $keys = array_filter($entity_type->getKeys()); 197 $keys = array_filter($entity_type->getKeys());
196 198
197 // Fail with an exception for non-fieldable entity types. 199 // Fail with an exception for non-fieldable entity types.
198 if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) { 200 if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
199 throw new \LogicException("Getting the base fields is not supported for entity type {$entity_type->getLabel()}."); 201 throw new \LogicException("Getting the base fields is not supported for entity type {$entity_type->getLabel()}.");
219 ->setDefaultValue(TRUE); 221 ->setDefaultValue(TRUE);
220 } 222 }
221 } 223 }
222 224
223 // Make sure that revisionable entity types are correctly defined. 225 // Make sure that revisionable entity types are correctly defined.
226 if ($entity_type->isRevisionable()) {
227 // Disable the BC layer to prevent a recursion, this only needs the
228 // revision_default key that is always set.
229 $field_name = $entity_type->getRevisionMetadataKeys(FALSE)['revision_default'];
230 $base_field_definitions[$field_name] = BaseFieldDefinition::create('boolean')
231 ->setLabel($this->t('Default revision'))
232 ->setDescription($this->t('A flag indicating whether this was a default revision when it was saved.'))
233 ->setStorageRequired(TRUE)
234 ->setInternal(TRUE)
235 ->setTranslatable(FALSE)
236 ->setRevisionable(TRUE);
237 }
238
239 // Make sure that revisionable and translatable entity types are correctly
240 // defined.
224 if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) { 241 if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
225 // The 'revision_translation_affected' field should always be defined. 242 // The 'revision_translation_affected' field should always be defined.
226 // This field has been added unconditionally in Drupal 8.4.0 and it is 243 // This field has been added unconditionally in Drupal 8.4.0 and it is
227 // overriding any pre-existing definition on purpose so that any 244 // overriding any pre-existing definition on purpose so that any
228 // differences are immediately available in the status report. 245 // differences are immediately available in the status report.