Skip to content
EntityTest.php 2.21 KiB
Newer Older
 * Definition of Drupal\entity_test\Plugin\Core\Entity\EntityTest.
namespace Drupal\entity_test\Plugin\Core\Entity;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
 *   id = "entity_test",
 *   label = @Translation("Test entity"),
 *   module = "entity_test",
 *   controllers = {
 *     "storage" = "Drupal\entity_test\EntityTestStorageController",
 *     "access" = "Drupal\entity_test\EntityTestAccessController",
 *     "form" = {
 *       "default" = "Drupal\entity_test\EntityTestFormController"
 *     },
 *     "translation" = "Drupal\translation_entity\EntityTranslationControllerNG"
 *   },
 *   base_table = "entity_test",
 *   fieldable = TRUE,
 *   entity_keys = {
 *     "id" = "id",
 *   },
 *   menu_base_path = "entity-test/manage/%entity_test"
   * @var \Drupal\Core\Entity\Field\FieldInterface
   * @var \Drupal\Core\Entity\Field\FieldInterface
  /**
   * The bundle of the test entity.
   *
   * @var \Drupal\Core\Entity\Field\FieldInterface
   */
  public $type;

   * @var \Drupal\Core\Entity\Field\FieldInterface
   * @var \Drupal\Core\Entity\Field\FieldInterface
   * Initialize the object. Invoked upon construction and wake up.
  protected function init() {
    parent::init();
    // We unset all defined properties, so magic getters apply.
    unset($this->id);
    unset($this->uuid);
    unset($this->name);
    unset($this->user_id);

  /**
   * Overrides Drupal\entity\Entity::label().
   */
  public function label($langcode = LANGUAGE_DEFAULT) {
    $info = $this->entityInfo();
    if (isset($info['entity_keys']['label']) && $info['entity_keys']['label'] == 'name') {
      return $this->getTranslation($langcode)->name->value;
    }
    else {
      return parent::label($langcode);
    }