X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FEntityType.php;h=c6f320fd6e60c6e03839e9a770a68403890cbcf5;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=9584ed3e26511dac2b420aa516f128d91d6fde20;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Entity/EntityType.php b/web/core/lib/Drupal/Core/Entity/EntityType.php index 9584ed3e2..c6f320fd6 100644 --- a/web/core/lib/Drupal/Core/Entity/EntityType.php +++ b/web/core/lib/Drupal/Core/Entity/EntityType.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Entity; use Drupal\Component\Plugin\Definition\PluginDefinition; -use Drupal\Component\Utility\Unicode; +use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Entity\Exception\EntityTypeIdLengthException; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; @@ -15,6 +15,7 @@ use Drupal\Core\StringTranslation\TranslatableMarkup; */ class EntityType extends PluginDefinition implements EntityTypeInterface { + use DependencySerializationTrait; use StringTranslationTrait; /** @@ -154,6 +155,13 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { */ protected $data_table = NULL; + /** + * Indicates whether the entity data is internal. + * + * @var bool + */ + protected $internal = FALSE; + /** * Indicates whether entities of this type have multilingual support. * @@ -288,7 +296,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { */ public function __construct($definition) { // Throw an exception if the entity type ID is longer than 32 characters. - if (Unicode::strlen($definition['id']) > static::ID_MAX_LENGTH) { + if (mb_strlen($definition['id']) > static::ID_MAX_LENGTH) { throw new EntityTypeIdLengthException('Attempt to create an entity type with an ID longer than ' . static::ID_MAX_LENGTH . " characters: {$definition['id']}."); } @@ -311,11 +319,16 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { $this->checkStorageClass($this->handlers['storage']); } - // Automatically add the EntityChanged constraint if the entity type tracks - // the changed time. + // Automatically add the "EntityChanged" constraint if the entity type + // tracks the changed time. if ($this->entityClassImplements(EntityChangedInterface::class)) { $this->addConstraint('EntityChanged'); } + // Automatically add the "EntityUntranslatableFields" constraint if we have + // an entity type supporting translatable fields and pending revisions. + if ($this->entityClassImplements(ContentEntityInterface::class)) { + $this->addConstraint('EntityUntranslatableFields'); + } // Ensure a default list cache tag is set. if (empty($this->list_cache_tags)) { @@ -349,6 +362,13 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { return $this; } + /** + * {@inheritdoc} + */ + public function isInternal() { + return $this->internal; + } + /** * {@inheritdoc} */ @@ -677,7 +697,15 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { * {@inheritdoc} */ public function getBundleLabel() { - return (string) $this->bundle_label; + // If there is no bundle label defined, try to provide some sensible + // fallbacks. + if (!empty($this->bundle_label)) { + return (string) $this->bundle_label; + } + elseif ($bundle_entity_type_id = $this->getBundleEntityType()) { + return (string) \Drupal::entityTypeManager()->getDefinition($bundle_entity_type_id)->getLabel(); + } + return (string) new TranslatableMarkup('@type_label bundle', ['@type_label' => $this->getLabel()], [], $this->getStringTranslation()); } /** @@ -741,7 +769,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { * {@inheritdoc} */ public function getLowercaseLabel() { - return Unicode::strtolower($this->getLabel()); + return mb_strtolower($this->getLabel()); } /** @@ -810,7 +838,6 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { return $this->group; } - /** * {@inheritdoc} */