EntityTestWithBundle.php 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php

namespace Drupal\entity_test\Entity;

use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;

/**
 * Defines the Test entity with bundle entity class.
 *
 * @ContentEntityType(
 *   id = "entity_test_with_bundle",
 *   label = @Translation("Test entity with bundle"),
 *   handlers = {
 *     "list_builder" = "Drupal\entity_test\EntityTestListBuilder",
 *     "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
18
 *     "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 *     "form" = {
 *       "default" = "\Drupal\Core\Entity\ContentEntityForm",
 *       "delete" = "\Drupal\Core\Entity\EntityDeleteForm"
 *     },
 *     "route_provider" = {
 *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
 *     },
 *   },
 *   base_table = "entity_test_with_bundle",
 *   admin_permission = "administer entity_test_with_bundle content",
 *   persistent_cache = FALSE,
 *   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *     "bundle" = "type",
 *     "label" = "name",
 *     "langcode" = "langcode",
 *   },
 *   bundle_entity_type = "entity_test_bundle",
 *   links = {
 *     "canonical" = "/entity_test_with_bundle/{entity_test_with_bundle}",
40
 *     "uuid" = "/entity_test_with_bundle/{entity_test_with_bundle}",
41 42
 *     "add-page" = "/entity_test_with_bundle/add",
 *     "add-form" = "/entity_test_with_bundle/add/{entity_test_bundle}",
43 44
 *     "edit-form" = "/entity_test_with_bundle/{entity_test_with_bundle}/edit",
 *     "delete-form" = "/entity_test_with_bundle/{entity_test_with_bundle}/delete",
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
 *   },
 * )
 */
class EntityTestWithBundle extends ContentEntityBase {

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields = parent::baseFieldDefinitions($entity_type);

    $fields['name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setDescription(t('The name of the test entity.'))
      ->setTranslatable(TRUE)
      ->setSetting('max_length', 32)
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'string',
        'weight' => -5,
      ])
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -5,
      ]);
    return $fields;
  }

}