Mercurial > hg > cmmr2012-drupal-site
comparison core/lib/Drupal/Core/Entity/ContentEntityBase.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
15 /** | 15 /** |
16 * Implements Entity Field API specific enhancements to the Entity class. | 16 * Implements Entity Field API specific enhancements to the Entity class. |
17 * | 17 * |
18 * @ingroup entity_api | 18 * @ingroup entity_api |
19 */ | 19 */ |
20 abstract class ContentEntityBase extends Entity implements \IteratorAggregate, ContentEntityInterface, TranslationStatusInterface { | 20 abstract class ContentEntityBase extends EntityBase implements \IteratorAggregate, ContentEntityInterface, TranslationStatusInterface { |
21 | 21 |
22 use EntityChangesDetectionTrait { | 22 use EntityChangesDetectionTrait { |
23 getFieldsToSkipFromTranslationChangesCheck as traitGetFieldsToSkipFromTranslationChangesCheck; | 23 getFieldsToSkipFromTranslationChangesCheck as traitGetFieldsToSkipFromTranslationChangesCheck; |
24 } | 24 } |
25 use SynchronizableEntityTrait; | |
25 | 26 |
26 /** | 27 /** |
27 * The plain data values of the contained fields. | 28 * The plain data values of the contained fields. |
28 * | 29 * |
29 * This always holds the original, unchanged values of the entity. The values | 30 * This always holds the original, unchanged values of the entity. The values |
426 * {@inheritdoc} | 427 * {@inheritdoc} |
427 */ | 428 */ |
428 public function isTranslatable() { | 429 public function isTranslatable() { |
429 // Check the bundle is translatable, the entity has a language defined, and | 430 // Check the bundle is translatable, the entity has a language defined, and |
430 // the site has more than one language. | 431 // the site has more than one language. |
431 $bundles = $this->entityManager()->getBundleInfo($this->entityTypeId); | 432 $bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->entityTypeId); |
432 return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual(); | 433 return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual(); |
433 } | 434 } |
434 | 435 |
435 /** | 436 /** |
436 * {@inheritdoc} | 437 * {@inheritdoc} |
676 /** | 677 /** |
677 * {@inheritdoc} | 678 * {@inheritdoc} |
678 */ | 679 */ |
679 public function getFieldDefinitions() { | 680 public function getFieldDefinitions() { |
680 if (!isset($this->fieldDefinitions)) { | 681 if (!isset($this->fieldDefinitions)) { |
681 $this->fieldDefinitions = $this->entityManager()->getFieldDefinitions($this->entityTypeId, $this->bundle()); | 682 $this->fieldDefinitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityTypeId, $this->bundle()); |
682 } | 683 } |
683 return $this->fieldDefinitions; | 684 return $this->fieldDefinitions; |
684 } | 685 } |
685 | 686 |
686 /** | 687 /** |
697 /** | 698 /** |
698 * {@inheritdoc} | 699 * {@inheritdoc} |
699 */ | 700 */ |
700 public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) { | 701 public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) { |
701 if ($operation == 'create') { | 702 if ($operation == 'create') { |
702 return $this->entityManager() | 703 return $this->entityTypeManager() |
703 ->getAccessControlHandler($this->entityTypeId) | 704 ->getAccessControlHandler($this->entityTypeId) |
704 ->createAccess($this->bundle(), $account, [], $return_as_object); | 705 ->createAccess($this->bundle(), $account, [], $return_as_object); |
705 } | 706 } |
706 return $this->entityManager() | 707 return $this->entityTypeManager() |
707 ->getAccessControlHandler($this->entityTypeId) | 708 ->getAccessControlHandler($this->entityTypeId) |
708 ->access($this, $operation, $account, $return_as_object); | 709 ->access($this, $operation, $account, $return_as_object); |
709 } | 710 } |
710 | 711 |
711 /** | 712 /** |
919 $translation->translationInitialize = FALSE; | 920 $translation->translationInitialize = FALSE; |
920 $translation->typedData = NULL; | 921 $translation->typedData = NULL; |
921 $translation->loadedRevisionId = &$this->loadedRevisionId; | 922 $translation->loadedRevisionId = &$this->loadedRevisionId; |
922 $translation->isDefaultRevision = &$this->isDefaultRevision; | 923 $translation->isDefaultRevision = &$this->isDefaultRevision; |
923 $translation->enforceRevisionTranslationAffected = &$this->enforceRevisionTranslationAffected; | 924 $translation->enforceRevisionTranslationAffected = &$this->enforceRevisionTranslationAffected; |
925 $translation->isSyncing = &$this->isSyncing; | |
924 | 926 |
925 return $translation; | 927 return $translation; |
926 } | 928 } |
927 | 929 |
928 /** | 930 /** |
956 throw new \InvalidArgumentException("The entity cannot be translated since it is language neutral ({$this->defaultLangcode})."); | 958 throw new \InvalidArgumentException("The entity cannot be translated since it is language neutral ({$this->defaultLangcode})."); |
957 } | 959 } |
958 | 960 |
959 // Initialize the translation object. | 961 // Initialize the translation object. |
960 /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */ | 962 /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */ |
961 $storage = $this->entityManager()->getStorage($this->getEntityTypeId()); | 963 $storage = $this->entityTypeManager()->getStorage($this->getEntityTypeId()); |
962 $this->translations[$langcode]['status'] = !isset($this->translations[$langcode]['status_existed']) ? static::TRANSLATION_CREATED : static::TRANSLATION_EXISTING; | 964 $this->translations[$langcode]['status'] = !isset($this->translations[$langcode]['status_existed']) ? static::TRANSLATION_CREATED : static::TRANSLATION_EXISTING; |
963 return $storage->createTranslation($this, $langcode, $values); | 965 return $storage->createTranslation($this, $langcode, $values); |
964 } | 966 } |
965 | 967 |
966 /** | 968 /** |
1216 $default_revision = $this->isDefaultRevision; | 1218 $default_revision = $this->isDefaultRevision; |
1217 $this->isDefaultRevision = &$default_revision; | 1219 $this->isDefaultRevision = &$default_revision; |
1218 | 1220 |
1219 $is_revision_translation_affected_enforced = $this->enforceRevisionTranslationAffected; | 1221 $is_revision_translation_affected_enforced = $this->enforceRevisionTranslationAffected; |
1220 $this->enforceRevisionTranslationAffected = &$is_revision_translation_affected_enforced; | 1222 $this->enforceRevisionTranslationAffected = &$is_revision_translation_affected_enforced; |
1223 | |
1224 $is_syncing = $this->isSyncing; | |
1225 $this->isSyncing = &$is_syncing; | |
1221 | 1226 |
1222 foreach ($this->fields as $name => $fields_by_langcode) { | 1227 foreach ($this->fields as $name => $fields_by_langcode) { |
1223 $this->fields[$name] = []; | 1228 $this->fields[$name] = []; |
1224 // Untranslatable fields may have multiple references for the same field | 1229 // Untranslatable fields may have multiple references for the same field |
1225 // object keyed by language. To avoid creating different field objects | 1230 // object keyed by language. To avoid creating different field objects |
1404 /** @var \Drupal\Core\Entity\ContentEntityBase $original */ | 1409 /** @var \Drupal\Core\Entity\ContentEntityBase $original */ |
1405 $original = $this->original ? $this->original : NULL; | 1410 $original = $this->original ? $this->original : NULL; |
1406 | 1411 |
1407 if (!$original) { | 1412 if (!$original) { |
1408 $id = $this->getOriginalId() !== NULL ? $this->getOriginalId() : $this->id(); | 1413 $id = $this->getOriginalId() !== NULL ? $this->getOriginalId() : $this->id(); |
1409 $original = $this->entityManager()->getStorage($this->getEntityTypeId())->loadUnchanged($id); | 1414 $original = $this->entityTypeManager()->getStorage($this->getEntityTypeId())->loadUnchanged($id); |
1410 } | 1415 } |
1411 | 1416 |
1412 // If the current translation has just been added, we have a change. | 1417 // If the current translation has just been added, we have a change. |
1413 $translated = count($this->translations) > 1; | 1418 $translated = count($this->translations) > 1; |
1414 if ($translated && !$original->hasTranslation($this->activeLangcode)) { | 1419 if ($translated && !$original->hasTranslation($this->activeLangcode)) { |