class EntityTest

Defines the test entity class.

Plugin annotation


@Plugin(
  id = "entity_test",
  label = @Translation("Test entity"),
  module = "entity_test",
  controller_class = "Drupal\entity_test\EntityTestStorageController",
  access_controller_class = "Drupal\entity_test\EntityTestAccessController",
  form_controller_class = {
    "default" = "Drupal\entity_test\EntityTestFormController"
  },
  translation_controller_class = "Drupal\entity_test\EntityTestTranslationController",
  base_table = "entity_test",
  data_table = "entity_test_property_data",
  revision_table = "entity_test_property_revision",
  fieldable = TRUE,
  entity_keys = {
    "id" = "id",
    "uuid" = "uuid",
    "revision" = "revision_id"
  },
  menu_base_path = "entity-test/manage/%entity_test"
)

Hierarchy

Expanded class hierarchy of EntityTest

1 file declares its use of EntityTest
entity_test.module in drupal/core/modules/system/tests/modules/entity_test/entity_test.module
Test module for the entity API providing an entity type for testing.

File

drupal/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php, line 39
Definition of Drupal\entity_test\Plugin\Core\Entity\EntityTest.

Namespace

Drupal\entity_test\Plugin\Core\Entity
View source
class EntityTest extends EntityNG {

  /**
   * The entity ID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $id;

  /**
   * The entity UUID.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $uuid;

  /**
   * The entity revision id.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $revision_id;

  /**
   * The name of the test entity.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $name;

  /**
   * The associated user.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $user_id;

  /**
   * Overrides Entity::__construct().
   */
  public function __construct(array $values, $entity_type) {
    parent::__construct($values, $entity_type);

    // We unset all defined properties, so magic getters apply.
    unset($this->id);
    unset($this->langcode);
    unset($this->uuid);
    unset($this->revision_id);
    unset($this->name);
    unset($this->user_id);
  }

  /**
   * Overrides Drupal\entity\Entity::label().
   */
  public function label($langcode = LANGUAGE_DEFAULT) {
    return $this
      ->getTranslation($langcode)->name->value;
  }

  /**
   * Implements Drupal\Core\Entity\EntityInterface::getRevisionId().
   */
  public function getRevisionId() {
    return $this
      ->get('revision_id')->value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
Entity::$entityType protected property The entity type.
Entity::$isDefaultRevision protected property Indicates whether this is the default revision. 1
Entity::$langcode public property The language code of the entity's default language. 4
Entity::$newRevision protected property Boolean indicating whether a new revision should be created on save.
Entity::access public function Implements AccessibleInterface::access(). Overrides AccessibleInterface::access
Entity::bundle public function Implements EntityInterface::bundle(). Overrides EntityInterface::bundle 4
Entity::delete public function Implements EntityInterface::delete(). Overrides EntityInterface::delete
Entity::enforceIsNew public function Implements EntityInterface::enforceIsNew(). Overrides EntityInterface::enforceIsNew
Entity::entityInfo public function Implements EntityInterface::entityInfo(). Overrides EntityInterface::entityInfo
Entity::entityType public function Implements EntityInterface::entityType(). Overrides EntityInterface::entityType
Entity::isDefaultRevision public function Implements Drupal\Core\Entity\EntityInterface::isDefaultRevision(). Overrides EntityInterface::isDefaultRevision 1
Entity::isNew public function Implements EntityInterface::isNew(). Overrides EntityInterface::isNew 1
Entity::isNewRevision public function Implements EntityInterface::isNewRevision(). Overrides EntityInterface::isNewRevision
Entity::save public function Implements EntityInterface::save(). Overrides EntityInterface::save 3
Entity::setNewRevision public function Implements EntityInterface::setNewRevision(). Overrides EntityInterface::setNewRevision
Entity::translations public function Returns the languages the entity is translated to.
Entity::uri public function Implements EntityInterface::uri(). Overrides EntityInterface::uri 1
EntityNG::$compatibilityMode protected property Whether the entity is in pre-Entity Field API compatibility mode.
EntityNG::$fields protected property The array of fields, each being an instance of FieldInterface.
EntityNG::$values protected property The plain data values of the contained fields.
EntityNG::createDuplicate public function Overrides Entity::createDuplicate(). Overrides Entity::createDuplicate
EntityNG::get public function Implements ComplexDataInterface::get(). Overrides Entity::get
EntityNG::getCompatibilityMode public function Returns whether the compatibility mode is active.
EntityNG::getIterator public function Implements IteratorAggregate::getIterator(). Overrides Entity::getIterator
EntityNG::getProperties public function Implements ComplexDataInterface::getProperties(). Overrides Entity::getProperties
EntityNG::getPropertyDefinition public function Implements ComplexDataInterface::getPropertyDefinition(). Overrides Entity::getPropertyDefinition
EntityNG::getPropertyDefinitions public function Implements ComplexDataInterface::getPropertyDefinitions(). Overrides Entity::getPropertyDefinitions
EntityNG::getPropertyValues public function Implements ComplexDataInterface::getPropertyValues(). Overrides Entity::getPropertyValues
EntityNG::getTranslatedField protected function Gets a translated field.
EntityNG::getTranslation public function Implements TranslatableInterface::getTranslation(). Overrides Entity::getTranslation
EntityNG::getTranslationLanguages public function Implements TranslatableInterface::getTranslationLanguages(). Overrides Entity::getTranslationLanguages
EntityNG::id public function Overrides Entity::id(). Overrides Entity::id
EntityNG::isEmpty public function Implements ComplexDataInterface::isEmpty(). Overrides Entity::isEmpty
EntityNG::language public function Implements TranslatableInterface::language(). Overrides Entity::language
EntityNG::set public function Implements ComplexDataInterface::set(). Overrides Entity::set
EntityNG::setCompatibilityMode public function Enables or disable the compatibility mode.
EntityNG::setPropertyValues public function Implements ComplexDataInterface::setPropertyValues(). Overrides Entity::setPropertyValues
EntityNG::updateOriginalValues public function Updates the original values with the interim changes.
EntityNG::uuid public function Overrides Entity::uuid(). Overrides Entity::uuid
EntityNG::__clone public function Implements a deep clone.
EntityNG::__get public function Magic getter: Gets the property in default language.
EntityNG::__isset public function Magic method.
EntityNG::__set public function Magic getter: Sets the property in default language.
EntityNG::__unset public function Magic method.
EntityTest::$id public property The entity ID.
EntityTest::$name public property The name of the test entity.
EntityTest::$revision_id public property The entity revision id.
EntityTest::$user_id public property The associated user.
EntityTest::$uuid public property The entity UUID.
EntityTest::getRevisionId public function Implements Drupal\Core\Entity\EntityInterface::getRevisionId(). Overrides Entity::getRevisionId
EntityTest::label public function Overrides Drupal\entity\Entity::label(). Overrides Entity::label
EntityTest::__construct public function Overrides Entity::__construct(). Overrides Entity::__construct