EntityTestBaseFieldDisplay.php 2.1 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\entity_test\Entity\EntityTestBaseFieldDisplay.
6 7 8 9
 */

namespace Drupal\entity_test\Entity;

10
use Drupal\Core\Entity\EntityTypeInterface;
11
use Drupal\Core\Field\BaseFieldDefinition;
12 13 14 15

/**
 * Defines a test entity class for base fields display.
 *
16
 * @ContentEntityType(
17 18 19
 *   id = "entity_test_base_field_display",
 *   label = @Translation("Test entity - base field display"),
 *   controllers = {
20
 *     "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
21
 *     "form" = {
22
 *       "default" = "Drupal\entity_test\EntityTestForm"
23
 *     },
24
 *     "translation" = "Drupal\content_translation\ContentTranslationHandler"
25 26 27 28 29 30 31 32 33 34
 *   },
 *   base_table = "entity_test",
 *   fieldable = TRUE,
 *   entity_keys = {
 *     "id" = "id",
 *     "uuid" = "uuid",
 *     "bundle" = "type"
 *   },
 *   links = {
 *     "edit-form" = "entity_test.edit_entity_test",
35 36
 *   },
 *   field_ui_base_route = "entity_test.admin_entity_test",
37 38 39 40 41 42 43
 * )
 */
class EntityTestBaseFieldDisplay extends EntityTest {

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

47
    $fields['test_no_display'] = BaseFieldDefinition::create('text')
48 49
      ->setLabel(t('Field with no display'));

50
    $fields['test_display_configurable'] = BaseFieldDefinition::create('text')
51 52 53 54 55 56 57 58 59 60 61 62
      ->setLabel(t('Field with configurable display'))
      ->setDisplayOptions('view', array(
        'type' => 'text_default',
        'weight' => 10,
      ))
      ->setDisplayConfigurable('view', TRUE)
      ->setDisplayOptions('form', array(
        'type' => 'text_textfield',
        'weight' => 10,
      ))
      ->setDisplayConfigurable('form', TRUE);

63
    $fields['test_display_non_configurable'] = BaseFieldDefinition::create('text')
64 65 66 67 68 69 70 71 72 73 74 75 76 77
      ->setLabel(t('Field with non-configurable display'))
      ->setDisplayOptions('view', array(
        'type' => 'text_default',
        'weight' => 11,
      ))
      ->setDisplayOptions('form', array(
        'type' => 'text_textfield',
        'weight' => 11,
      ));

    return $fields;
  }

}