public CommentManager::addBodyField($comment_type_id)
Creates a comment_body field.
Parameters
string $comment_type: The comment bundle.
Overrides CommentManagerInterface::addBodyField
File
- core/modules/comment/src/CommentManager.php, line 113
Class
- CommentManager
- Comment manager contains common functions to manage comment fields.
Namespace
Drupal\comment
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | public function addBodyField( $comment_type_id ) { if (!FieldConfig::loadByName( 'comment' , $comment_type_id , 'comment_body' )) { // Attaches the body field by default. $field = $this ->entityManager->getStorage( 'field_config' )->create( array ( 'label' => 'Comment' , 'bundle' => $comment_type_id , 'required' => TRUE, 'field_storage' => FieldStorageConfig::loadByName( 'comment' , 'comment_body' ), )); $field ->save(); // Assign widget settings for the 'default' form mode. entity_get_form_display( 'comment' , $comment_type_id , 'default' ) ->setComponent( 'comment_body' , array ( 'type' => 'text_textarea' , )) ->save(); // Assign display settings for the 'default' view mode. entity_get_display( 'comment' , $comment_type_id , 'default' ) ->setComponent( 'comment_body' , array ( 'label' => 'hidden' , 'type' => 'text_default' , 'weight' => 0, )) ->save(); } } |
Please login to continue.