TestEntity.php 1.58 KB
Newer Older
1 2
<?php

3
/**
4
 * @file
5
 * Contains Drupal\field_test\Plugin\Core\Entity\TestEntity.
6 7
 */

8
namespace Drupal\field_test\Plugin\Core\Entity;
9

10
use Drupal\Core\Entity\Entity;
11
use Drupal\Core\Entity\Annotation\EntityType;
12
use Drupal\Core\Annotation\Translation;
13 14 15

/**
 * Test entity class.
16
 *
17
 * @EntityType(
18 19 20
 *   id = "test_entity",
 *   label = @Translation("Test Entity"),
 *   module = "field_test",
21 22 23 24 25 26
 *   controllers = {
 *     "storage" = "Drupal\field_test\TestEntityController",
 *     "render" = "Drupal\Core\Entity\EntityRenderController",
 *     "form" = {
 *       "default" = "Drupal\field_test\TestEntityFormController"
 *     }
27 28 29 30 31 32 33 34 35 36 37
 *   },
 *   field_cache = FALSE,
 *   base_table = "test_entity",
 *   revision_table = "test_entity_revision",
 *   fieldable = TRUE,
 *   entity_keys = {
 *     "id" = "ftid",
 *     "revision" = "ftvid",
 *     "bundle" = "fttype"
 *   }
 * )
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
 */
class TestEntity extends Entity {

  /**
   * Primary key.
   *
   * @var integer
   */
  public $ftid;

  /**
   * Revision key.
   *
   * @var integer
   */
  public $ftvid;

  /**
   * Bundle
   *
   * @var string
   */
  public $fttype;

62 63 64 65 66 67 68
  /**
   * Label property
   *
   * @var string
   */
  public $ftlabel;

69
  /**
70
   * Overrides Drupal\Core\Entity\Entity::id().
71 72 73 74 75 76
   */
  public function id() {
    return $this->ftid;
  }

  /**
77
   * Overrides Drupal\Core\Entity\Entity::getRevisionId().
78 79 80 81 82 83
   */
  public function getRevisionId() {
    return $this->ftvid;
  }

  /**
84
   * Overrides Drupal\Core\Entity\Entity::bundle().
85 86 87 88 89 90
   */
  public function bundle() {
    return !empty($this->fttype) ? $this->fttype : $this->entityType();
  }
}