CommentTestBaseField.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Drupal\comment_base_field_test\Entity;
  3. use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
  4. use Drupal\Core\Entity\EntityTypeInterface;
  5. use Drupal\Core\Field\BaseFieldDefinition;
  6. use Drupal\entity_test\Entity\EntityTest;
  7. /**
  8. * Defines a test entity class for comment as a base field.
  9. *
  10. * @ContentEntityType(
  11. * id = "comment_test_base_field",
  12. * label = @Translation("Test comment - base field"),
  13. * base_table = "comment_test_base_field",
  14. * entity_keys = {
  15. * "id" = "id",
  16. * "uuid" = "uuid",
  17. * "bundle" = "type"
  18. * },
  19. * )
  20. */
  21. class CommentTestBaseField extends EntityTest {
  22. public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  23. $fields = parent::baseFieldDefinitions($entity_type);
  24. $fields['test_comment'] = BaseFieldDefinition::create('comment')
  25. ->setLabel(t('A comment field'))
  26. ->setSetting('comment_type', 'test_comment_type')
  27. ->setDefaultValue([
  28. 'status' => CommentItemInterface::OPEN,
  29. ]);
  30. return $fields;
  31. }
  32. }