Wednesday, February 26, 2020

How to customize the comments form in drupal 8

Step 1:- I would do it:

1) Create new file: testmodule.info.yml.

name: testmodule
description: Testmodule
type: module
core: 8.x

2) Create new file: testmodule.module

<?php


function testmodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

  if ($form_id=='comment_comment_form') {

    //add class subject
    $form['subject']['widget']['0']['value']['#attributes']['class'][]='newclass_subject';

    //add placeholder subject
    $form['subject']['widget']['0']['value']['#attributes']['placeholder'] = t('Placeholder Subject');


    //add class body
    $form['comment_body']['widget']['0']['#attributes']['class'][]='newclass_body';

    //add placeholder body
    $form['comment_body']['widget']['0']['#attributes']['placeholder'] = t('Placeholder Body');

  }

}

No comments:

Post a Comment

If you have any problem please let me know.