Showing posts with label Theme. Show all posts
Showing posts with label Theme. Show all posts

Saturday, November 17, 2018

Customization in drupal 8 core contact form using form alter

How to change Drupal 8 Core Contact form fleld label :-

 If you want to change Contact form "Message" field label you can use "hook_form_alter" .

either you can create a custom module or either you can add form alter in your theme file also.

 
function your_theme_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
       if ($form_id == 'contact_message_feedback_form') {
        $form['message']['widget'][0]['value']['#title'] = t("My Custom Body Label");
     }
} 


Add placeholder in default search using form alter

function your_theme_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    if (in_array($form_id, ['search_block_form', 'search_form'])) {
        $form['keys']['#attributes']['placeholder'] = t('Search...');
    }
   }if ($form_id == 'contact_message_feedback_form') {
  $form['actions']['submit']['#value'] = t("My Altered submit button text here");
  $form['subject']['widget'][0]['value']['#title'] = t ("My Altered title here");
  $form['message']['widget'][0]['value']['#title'] = t("My custom body text here");
        //$form['message']['widget'][0]['value']['#title'] = t("My Custom Body Label");
  $form['#suffix'] = "<div class='extra-text'><p>Show some text before the comment form.</p></div>";
     }
} 

Saturday, October 20, 2018

How to add missing node id in Drupal 8

Add Missing Node id in drupal 8 :- 




By default node id will not be there in the drupal 8. to enable this you have to add this code in your .theme file ->

   function THEMENAME_preprocess_html(&$variables) {  
    // Add node id to the body class.  
    $node = \Drupal::routeMatch()->getParameter('node');  
    if($node) {  
     $variables['attributes']['class'][] = 'node-' . $node->id();  
    }  
   }