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;
*/
class EntityType extends PluginDefinition implements EntityTypeInterface {
+ use DependencySerializationTrait;
use StringTranslationTrait;
/**
*/
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.
*
*/
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']}.");
}
'bundle' => '',
'langcode' => '',
'default_langcode' => 'default_langcode',
+ 'revision_translation_affected' => 'revision_translation_affected',
];
$this->handlers += [
'access' => 'Drupal\Core\Entity\EntityAccessControlHandler',
$this->checkStorageClass($this->handlers['storage']);
}
- // Automatically add the EntityChanged constraint if the entity type tracks
- // the changed time.
- if ($this->entityClassImplements(EntityChangedInterface::class) ) {
+ // 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)) {
return $this;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function isInternal() {
+ return $this->internal;
+ }
+
/**
* {@inheritdoc}
*/
* {@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());
}
/**
* {@inheritdoc}
*/
public function getLowercaseLabel() {
- return Unicode::strtolower($this->getLabel());
+ return mb_strtolower($this->getLabel());
}
/**
return $this->group;
}
-
/**
* {@inheritdoc}
*/