function Comment::preCreate

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

Overrides EntityBase::preCreate

File

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

Class

Comment
Defines the comment entity class.

Namespace

Drupal\comment\Entity

Code

public static function preCreate(EntityStorageInterface $storage, array &$values) {
    if (empty($values['comment_type']) && !empty($values['field_name']) && !empty($values['entity_type'])) {
        $fields = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($values['entity_type']);
        $values['comment_type'] = $fields[$values['field_name']]->getSetting('comment_type');
    }
}

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