CommentTestBaseField.php

Same filename in other branches
  1. 9 core/modules/comment/tests/modules/comment_base_field_test/src/Entity/CommentTestBaseField.php
  2. 8.9.x core/modules/comment/tests/modules/comment_base_field_test/src/Entity/CommentTestBaseField.php
  3. 10 core/modules/comment/tests/modules/comment_base_field_test/src/Entity/CommentTestBaseField.php

Namespace

Drupal\comment_base_field_test\Entity

File

core/modules/comment/tests/modules/comment_base_field_test/src/Entity/CommentTestBaseField.php

View source
<?php

declare (strict_types=1);
namespace Drupal\comment_base_field_test\Entity;

use Drupal\Core\Entity\Attribute\ContentEntityType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\entity_test\Entity\EntityTest;

/**
 * Defines a test entity class for comment as a base field.
 */
class CommentTestBaseField extends EntityTest {
    public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
        $fields = parent::baseFieldDefinitions($entity_type);
        $fields['test_comment'] = BaseFieldDefinition::create('comment')->setLabel(t('A comment field'))
            ->setSetting('comment_type', 'test_comment_type')
            ->setDefaultValue([
            'status' => CommentItemInterface::OPEN,
        ]);
        return $fields;
    }

}

Classes

Title Deprecated Summary
CommentTestBaseField Defines a test entity class for comment as a base field.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.