ContentEntityType.php

Same filename in this branch
  1. 10 core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php
Same filename in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityType.php
  2. 9 core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php
  3. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityType.php
  4. 8.9.x core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php
  5. 11.x core/lib/Drupal/Core/Entity/ContentEntityType.php
  6. 11.x core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php

Namespace

Drupal\Core\Entity

File

core/lib/Drupal/Core/Entity/ContentEntityType.php

View source
<?php

namespace Drupal\Core\Entity;


/**
 * Provides an implementation of a content entity type and its metadata.
 */
class ContentEntityType extends EntityType implements ContentEntityTypeInterface {
    
    /**
     * An array of entity revision metadata keys.
     *
     * @var array
     */
    // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName
    protected $revision_metadata_keys = [];
    
    /**
     * {@inheritdoc}
     */
    public function __construct($definition) {
        parent::__construct($definition);
        $this->handlers += [
            'storage' => 'Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage',
            'view_builder' => 'Drupal\\Core\\Entity\\EntityViewBuilder',
        ];
        $this->revision_metadata_keys += [
            'revision_default' => 'revision_default',
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getConfigDependencyKey() {
        return 'content';
    }
    
    /**
     * {@inheritdoc}
     *
     * @throws \InvalidArgumentException
     *   If the provided class does not implement
     *   \Drupal\Core\Entity\ContentEntityStorageInterface.
     *
     * @see \Drupal\Core\Entity\ContentEntityStorageInterface
     */
    protected function checkStorageClass($class) {
        $required_interface = ContentEntityStorageInterface::class;
        if (!is_subclass_of($class, $required_interface)) {
            throw new \InvalidArgumentException("{$class} does not implement {$required_interface}");
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRevisionMetadataKeys() {
        return $this->revision_metadata_keys;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRevisionMetadataKey($key) {
        $keys = $this->getRevisionMetadataKeys();
        return $keys[$key] ?? FALSE;
    }
    
    /**
     * {@inheritdoc}
     */
    public function hasRevisionMetadataKey($key) {
        $keys = $this->getRevisionMetadataKeys();
        return isset($keys[$key]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function setRevisionMetadataKey($key, $field_name) {
        if ($field_name !== NULL) {
            $this->revision_metadata_keys[$key] = $field_name;
        }
        else {
            unset($this->revision_metadata_keys[$key]);
        }
        return $this;
    }

}

Classes

Title Deprecated Summary
ContentEntityType Provides an implementation of a content entity type and its metadata.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.