config('hfs_body_scripts.settings')->get(); $form['hfs_body'] = [ '#type' => 'fieldset', '#title' => $this->t('Add Scripts and Styles in body'), '#description' => $this->t('All the defined scripts and styles in this section would be added next to body tag.'), ]; $form['hfs_body']['styles'] = [ '#type' => 'textarea', '#title' => $this->t('Body Styles'), '#default_value' => isset($body_section['styles']) ? $body_section['styles'] : '', '#description' => $this->t('

You can add multiple stylesheets here with multiple ways, For example:

1. <link type="text/css" rel="stylesheet" href="http://www.example.com/style.css" media="all" />

2. <link type="text/css" rel="stylesheet" href="/style.css" media="all" />

3. <style>#header { color: grey; }</style>

'), '#rows' => 10, ]; $form['hfs_body']['scripts'] = [ '#type' => 'textarea', '#title' => $this->t('Body Scripts'), '#default_value' => isset($body_section['scripts']) ? $body_section['scripts'] : '', '#description' => $this->t('

On mostly sites, this section is used to add the Google Tag Manager. Like:

1. <!-- Google Tag Manager --><noscript>Write Your code here</script><!-- End Google Tag Manager -->

You can also add multiple scripts here with multiple ways, For example:

1. <script type="text/javascript" src="http://www.example.com/script.js"></script>

2. <script type="text/javascript" src="/script.js"></script>

3. <script type="text/javascript">console.log("HFS Body");</script>

'), '#rows' => 10, ]; return parent::buildForm($form, $form_state); } /** * Implements FormBuilder::submitForm(). * * Serialize the user's settings and save it to the Drupal's config Table. */ public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); $this->configFactory() ->getEditable('hfs_body_scripts.settings') ->set('styles', $values['styles']) ->set('scripts', $values['scripts']) ->save(); drupal_set_message($this->t('Your Settings have been saved.'), 'status'); } }