function Comment::baseFieldDefinitions

Same name and namespace in other branches
  1. 9 core/modules/comment/src/Entity/Comment.php \Drupal\comment\Entity\Comment::baseFieldDefinitions()
  2. 10 core/modules/comment/src/Entity/Comment.php \Drupal\comment\Entity\Comment::baseFieldDefinitions()
  3. 11.x core/modules/comment/src/Entity/Comment.php \Drupal\comment\Entity\Comment::baseFieldDefinitions()

Overrides ContentEntityBase::baseFieldDefinitions

File

core/modules/comment/src/Entity/Comment.php, line 224

Class

Comment
Defines the comment entity class.

Namespace

Drupal\comment\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);
    $fields += static::publishedBaseFieldDefinitions($entity_type);
    $fields += static::ownerBaseFieldDefinitions($entity_type);
    $fields['cid']->setLabel(t('Comment ID'))
        ->setDescription(t('The comment ID.'));
    $fields['uuid']->setDescription(t('The comment UUID.'));
    $fields['comment_type']->setLabel(t('Comment Type'))
        ->setDescription(t('The comment type.'));
    $fields['langcode']->setDescription(t('The comment language code.'));
    // Set the default value callback for the status field.
    $fields['status']->setDefaultValueCallback('Drupal\\comment\\Entity\\Comment::getDefaultStatus');
    $fields['pid'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Parent ID'))
        ->setDescription(t('The parent comment ID if this is a reply to a comment.'))
        ->setSetting('target_type', 'comment');
    $fields['entity_id'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Entity ID'))
        ->setDescription(t('The ID of the entity of which this comment is a reply.'))
        ->setRequired(TRUE);
    $fields['subject'] = BaseFieldDefinition::create('string')->setLabel(t('Subject'))
        ->setTranslatable(TRUE)
        ->setSetting('max_length', 64)
        ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        // Default comment body field has weight 20.
'weight' => 10,
    ])
        ->setDisplayConfigurable('form', TRUE);
    $fields['uid']->setDescription(t('The user ID of the comment author.'));
    $fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Name'))
        ->setDescription(t("The comment author's name."))
        ->setTranslatable(TRUE)
        ->setSetting('max_length', 60)
        ->setDefaultValue('');
    $fields['mail'] = BaseFieldDefinition::create('email')->setLabel(t('Email'))
        ->setDescription(t("The comment author's email address."))
        ->setTranslatable(TRUE);
    $fields['homepage'] = BaseFieldDefinition::create('uri')->setLabel(t('Homepage'))
        ->setDescription(t("The comment author's home page address."))
        ->setTranslatable(TRUE)
        ->setSetting('max_length', 255);
    $fields['hostname'] = BaseFieldDefinition::create('string')->setLabel(t('Hostname'))
        ->setDescription(t("The comment author's hostname."))
        ->setTranslatable(TRUE)
        ->setSetting('max_length', 128)
        ->setDefaultValueCallback(static::class . '::getDefaultHostname');
    $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Created'))
        ->setDescription(t('The time that the comment was created.'))
        ->setTranslatable(TRUE);
    $fields['changed'] = BaseFieldDefinition::create('changed')->setLabel(t('Changed'))
        ->setDescription(t('The time that the comment was last edited.'))
        ->setTranslatable(TRUE);
    $fields['thread'] = BaseFieldDefinition::create('string')->setLabel(t('Thread place'))
        ->setDescription(t("The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length."))
        ->setSetting('max_length', 255);
    $fields['entity_type'] = BaseFieldDefinition::create('string')->setLabel(t('Entity type'))
        ->setRequired(TRUE)
        ->setDescription(t('The entity type to which this comment is attached.'))
        ->setSetting('is_ascii', TRUE)
        ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);
    $fields['field_name'] = BaseFieldDefinition::create('string')->setLabel(t('Comment field name'))
        ->setRequired(TRUE)
        ->setDescription(t('The field name through which this comment was added.'))
        ->setSetting('is_ascii', TRUE)
        ->setSetting('max_length', FieldStorageConfig::NAME_MAX_LENGTH);
    return $fields;
}

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