Fix Drupal 8 Coding Standards

This commit is contained in:
samiahmedsiddiqui 2017-09-18 11:41:56 +05:00
parent 80fb9de84f
commit 98161a6384
9 changed files with 166 additions and 117 deletions

View File

@ -4,17 +4,17 @@ from the front-end. You don't need to open any file for this purpose.
INSTALLATION INSTRUCTIONS INSTALLATION INSTRUCTIONS
------------------------- -------------------------
1. Copy the files included in the tarball into a directory named "header_and_footer_scripts" in 1. Copy the files included in the tarball into a directory named
your Drupal modules/ directory. "header_and_footer_scripts" in your Drupal modules/ directory.
2. Login as site administrator. 2. Login as site administrator.
3. Enable the HFS (Header Footer Scripts) module on the Administer -> Modules 3. Enable the HFS (Header Footer Scripts) module on the
page. Administer -> Modules page.
4. Add styles and scripts in settings on the Administer -> Configuration -> 4. Add styles and scripts in settings on the Administer ->
Development -> HFS (Header Footer Scripts) Page. Configuration -> Development -> HFS (Header Footer Scripts) Page.
5. Enjoy. 5. Enjoy.
NOTES NOTES
----- -----
This module adds the styles and scripts on all over the site. There are 2 This module adds the styles and scripts on all over the site.
setting pages. There are 2 setting pages.
These setting pages are allow you add the scripts in the desired region. These setting pages are allow you add the scripts in the desired region.

View File

@ -9,6 +9,10 @@
* Implements hook_uninstall(). * Implements hook_uninstall().
*/ */
function header_and_footer_scripts_uninstall() { function header_and_footer_scripts_uninstall() {
\Drupal::service('config.factory')->getEditable('hfs_body_scripts.settings')->delete(); \Drupal::service('config.factory')
\Drupal::service('config.factory')->getEditable('hfs_footer_scripts.settings')->delete(); ->getEditable('hfs_body_scripts.settings')
->delete();
\Drupal::service('config.factory')
->getEditable('hfs_footer_scripts.settings')
->delete();
} }

View File

@ -2,37 +2,43 @@
/** /**
* @file * @file
* Enables Drupal to add scripts and styles from frontend on all over the site. * Enables Drupal to add scripts and styles from frontend
* on all over the site.
*/ */
/** /**
* Implements hook_page_top(). * Implements hook_page_top().
* *
* Add scripts after the body tag on overall the site which are defined on the settings page. * Add scripts after the body tag on overall the site
* which are defined on the settings page.
*/ */
function header_and_footer_scripts_page_top(array &$page_top) { function header_and_footer_scripts_page_top(array &$page_top) {
$body_section = \Drupal::config('hfs_body_scripts.settings')->get(); $body_section = \Drupal::config('hfs_body_scripts.settings')->get();
if (isset($body_section['styles']) && !empty($body_section['styles'])) { if (isset($body_section['styles']) && !empty($body_section['styles'])) {
$output_styles = preg_split("/(<\/style>|\/>)/", $body_section['styles']); $output_styles = preg_split("/(<\/style>|\/>)/", $body_section['styles']);
$i = 1; $i = 1;
foreach ($output_styles as $row) { foreach ($output_styles as $row) {
if (empty($row)) continue; if (empty($row)) {
continue;
}
$style_tag = 'style'; $style_tag = 'style';
$style_attr = ''; $style_attr = '';
$value = ''; $value = '';
$style_attributes = preg_replace('/(<style|<link)/', '', $row, 1); $style_attributes = preg_replace('/(<style|<link)/', '', $row, 1);
$get_style_attr = preg_split('/(>)/', $style_attributes, 2); $get_style_attr = preg_split('/(>)/', $style_attributes, 2);
if (isset($get_style_attr[1])) if (isset($get_style_attr[1])) {
$value = $get_style_attr[1]; $value = $get_style_attr[1];
}
$get_style_tag = preg_split('/<link/', $row, 2); $get_style_tag = preg_split('/<link/', $row, 2);
if (isset($get_style_tag[1])) if (isset($get_style_tag[1])) {
$style_tag = 'link'; $style_tag = 'link';
}
if (isset($get_style_attr[0]) && !empty($get_style_attr[0])) { if (isset($get_style_attr[0]) && !empty($get_style_attr[0])) {
$get_attr = preg_replace('/(\'|\")/', '', $get_style_attr[0]); $get_attr = preg_replace('/(\'|\")/', '', $get_style_attr[0]);
@ -41,23 +47,27 @@ function header_and_footer_scripts_page_top(array &$page_top) {
$fetch_attr = explode(',', $get_attr); $fetch_attr = explode(',', $get_attr);
foreach ($fetch_attr as $attr) { foreach ($fetch_attr as $attr) {
if (empty($attr)) continue; if (empty($attr)) {
continue;
}
$attr_key_value = explode('=', $attr); $attr_key_value = explode('=', $attr);
if (isset($attr_key_value[0]) && isset($attr_key_value[1])) if (isset($attr_key_value[0]) && isset($attr_key_value[1])) {
$style_attr[$attr_key_value[0]] = $attr_key_value[1]; $style_attr[$attr_key_value[0]] = $attr_key_value[1];
else } else {
$style_attr[$attr_key_value[0]] = $attr_key_value[0]; $style_attr[$attr_key_value[0]] = $attr_key_value[0];
}
} }
} }
$page_top['top_styles_'.$i] = [ $page_top['top_styles_' . $i] = [
'#type' => 'html_tag', '#type' => 'html_tag',
'#tag' => $style_tag, '#tag' => $style_tag,
'#value' => $value '#value' => $value,
]; ];
if (is_array($style_attr)) if (is_array($style_attr)) {
$page_top['top_styles_'.$i]['#attributes'] = $style_attr; $page_top['top_styles_' . $i]['#attributes'] = $style_attr;
}
$i++; $i++;
} }
} }
@ -66,7 +76,9 @@ function header_and_footer_scripts_page_top(array &$page_top) {
$i = 1; $i = 1;
foreach ($output_scripts as $row) { foreach ($output_scripts as $row) {
if (empty($row)) continue; if (empty($row)) {
continue;
}
$script_tag = 'script'; $script_tag = 'script';
$script_attr = ''; $script_attr = '';
@ -75,13 +87,15 @@ function header_and_footer_scripts_page_top(array &$page_top) {
$script_attributes = preg_replace('/(<script|<noscript)/', '', $row, 1); $script_attributes = preg_replace('/(<script|<noscript)/', '', $row, 1);
$get_script_attr = preg_split('/(>)/', $script_attributes, 2); $get_script_attr = preg_split('/(>)/', $script_attributes, 2);
if (isset($get_script_attr[1])) if (isset($get_script_attr[1])) {
$value = $get_script_attr[1]; $value = $get_script_attr[1];
}
$get_script_tag = preg_split('/<noscript/', $row, 2); $get_script_tag = preg_split('/<noscript/', $row, 2);
if (isset($get_script_tag[1])) if (isset($get_script_tag[1])) {
$script_tag = 'noscript'; $script_tag = 'noscript';
}
if (isset($get_script_attr[0]) && !empty($get_script_attr[0])) { if (isset($get_script_attr[0]) && !empty($get_script_attr[0])) {
$get_attr = preg_replace('/(\'|\")/', '', $get_script_attr[0]); $get_attr = preg_replace('/(\'|\")/', '', $get_script_attr[0]);
@ -90,23 +104,27 @@ function header_and_footer_scripts_page_top(array &$page_top) {
$fetch_attr = explode(',', $get_attr); $fetch_attr = explode(',', $get_attr);
foreach ($fetch_attr as $attr) { foreach ($fetch_attr as $attr) {
if (empty($attr)) continue; if (empty($attr)) {
continue;
}
$attr_key_value = explode('=', $attr); $attr_key_value = explode('=', $attr);
if (isset($attr_key_value[0]) && isset($attr_key_value[1])) if (isset($attr_key_value[0]) && isset($attr_key_value[1])) {
$script_attr[$attr_key_value[0]] = $attr_key_value[1]; $script_attr[$attr_key_value[0]] = $attr_key_value[1];
else } else {
$script_attr[$attr_key_value[0]] = $attr_key_value[0]; $script_attr[$attr_key_value[0]] = $attr_key_value[0];
}
} }
} }
$page_top['top_scripts_'.$i] = [ $page_top['top_scripts_' . $i] = [
'#type' => 'html_tag', '#type' => 'html_tag',
'#tag' => $script_tag, '#tag' => $script_tag,
'#value' => $value '#value' => $value,
]; ];
if (is_array($script_attr)) if (is_array($script_attr)) {
$page_top['top_scripts_'.$i]['#attributes'] = $script_attr; $page_top['top_scripts_'.$i]['#attributes'] = $script_attr;
}
$i++; $i++;
} }
} }
@ -115,7 +133,8 @@ function header_and_footer_scripts_page_top(array &$page_top) {
/** /**
* Implements hook_page_bottom(). * Implements hook_page_bottom().
* *
* Add scripts before the Footer tag on overall the site which are defined on the settings page. * Add scripts before the Footer tag on overall the site
* which are defined on the settings page.
*/ */
function header_and_footer_scripts_page_bottom(array &$page_bottom) { function header_and_footer_scripts_page_bottom(array &$page_bottom) {
$footer_section = \Drupal::config('hfs_footer_scripts.settings')->get(); $footer_section = \Drupal::config('hfs_footer_scripts.settings')->get();
@ -124,22 +143,26 @@ function header_and_footer_scripts_page_bottom(array &$page_bottom) {
$i = 1; $i = 1;
foreach ($output_styles as $row) { foreach ($output_styles as $row) {
if (empty($row)) continue; if (empty($row)) {
continue;
}
$style_tag = 'style'; $style_tag = 'style';
$style_attr = ''; $style_attr = '';
$value = ''; $value = '';
$style_attributes = preg_replace('/(<style|<link)/', '', $row, 1); $style_attributes = preg_replace('/(<style|<link)/', '', $row, 1);
$get_style_attr = preg_split('/(>)/', $style_attributes, 2); $get_style_attr = preg_split('/(>)/', $style_attributes, 2);
if (isset($get_style_attr[1])) if (isset($get_style_attr[1])) {
$value = $get_style_attr[1]; $value = $get_style_attr[1];
}
$get_style_tag = preg_split('/<link/', $row, 2); $get_style_tag = preg_split('/<link/', $row, 2);
if (isset($get_style_tag[1])) if (isset($get_style_tag[1])) {
$style_tag = 'link'; $style_tag = 'link';
}
if (isset($get_style_attr[0]) && !empty($get_style_attr[0])) { if (isset($get_style_attr[0]) && !empty($get_style_attr[0])) {
$get_attr = preg_replace('/(\'|\")/', '', $get_style_attr[0]); $get_attr = preg_replace('/(\'|\")/', '', $get_style_attr[0]);
@ -148,23 +171,27 @@ function header_and_footer_scripts_page_bottom(array &$page_bottom) {
$fetch_attr = explode(',', $get_attr); $fetch_attr = explode(',', $get_attr);
foreach ($fetch_attr as $attr) { foreach ($fetch_attr as $attr) {
if (empty($attr)) continue; if (empty($attr)) {
continue;
}
$attr_key_value = explode('=', $attr); $attr_key_value = explode('=', $attr);
if (isset($attr_key_value[0]) && isset($attr_key_value[1])) if (isset($attr_key_value[0]) && isset($attr_key_value[1])) {
$style_attr[$attr_key_value[0]] = $attr_key_value[1]; $style_attr[$attr_key_value[0]] = $attr_key_value[1];
else } else {
$style_attr[$attr_key_value[0]] = $attr_key_value[0]; $style_attr[$attr_key_value[0]] = $attr_key_value[0];
}
} }
} }
$page_bottom['bottom_styles_'.$i] = [ $page_bottom['bottom_styles_' . $i] = [
'#type' => 'html_tag', '#type' => 'html_tag',
'#tag' => $style_tag, '#tag' => $style_tag,
'#value' => $value '#value' => $value,
]; ];
if (is_array($style_attr)) if (is_array($style_attr)) {
$page_bottom['bottom_styles_'.$i]['#attributes'] = $style_attr; $page_bottom['bottom_styles_' . $i]['#attributes'] = $style_attr;
}
$i++; $i++;
} }
} }
@ -182,13 +209,15 @@ function header_and_footer_scripts_page_bottom(array &$page_bottom) {
$script_attributes = preg_replace('/(<script|<noscript)/', '', $row, 1); $script_attributes = preg_replace('/(<script|<noscript)/', '', $row, 1);
$get_script_attr = preg_split('/(>)/', $script_attributes, 2); $get_script_attr = preg_split('/(>)/', $script_attributes, 2);
if (isset($get_script_attr[1])) if (isset($get_script_attr[1])) {
$value = $get_script_attr[1]; $value = $get_script_attr[1];
}
$get_script_tag = preg_split('/<noscript/', $row, 2); $get_script_tag = preg_split('/<noscript/', $row, 2);
if (isset($get_script_tag[1])) if (isset($get_script_tag[1])) {
$script_tag = 'noscript'; $script_tag = 'noscript';
}
if (isset($get_script_attr[0]) && !empty($get_script_attr[0])) { if (isset($get_script_attr[0]) && !empty($get_script_attr[0])) {
$get_attr = preg_replace('/(\'|\")/', '', $get_script_attr[0]); $get_attr = preg_replace('/(\'|\")/', '', $get_script_attr[0]);
@ -197,23 +226,27 @@ function header_and_footer_scripts_page_bottom(array &$page_bottom) {
$fetch_attr = explode(',', $get_attr); $fetch_attr = explode(',', $get_attr);
foreach ($fetch_attr as $attr) { foreach ($fetch_attr as $attr) {
if (empty($attr)) continue; if (empty($attr)) {
continue;
}
$attr_key_value = explode('=', $attr); $attr_key_value = explode('=', $attr);
if (isset($attr_key_value[0]) && isset($attr_key_value[1])) if (isset($attr_key_value[0]) && isset($attr_key_value[1])) {
$script_attr[$attr_key_value[0]] = $attr_key_value[1]; $script_attr[$attr_key_value[0]] = $attr_key_value[1];
else } else {
$script_attr[$attr_key_value[0]] = $attr_key_value[0]; $script_attr[$attr_key_value[0]] = $attr_key_value[0];
}
} }
} }
$page_bottom['bottom_scripts_'.$i] = [ $page_bottom['bottom_scripts_' . $i] = [
'#type' => 'html_tag', '#type' => 'html_tag',
'#tag' => $script_tag, '#tag' => $script_tag,
'#value' => $value '#value' => $value,
]; ];
if (is_array($script_attr)) if (is_array($script_attr)) {
$page_bottom['bottom_scripts_'.$i]['#attributes'] = $script_attr; $page_bottom['bottom_scripts_' . $i]['#attributes'] = $script_attr;
}
$i++; $i++;
} }
} }

View File

@ -6,48 +6,52 @@ use Drupal\Core\Form\ConfigFormBase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
/**
* This Class Provides the settings page for adding CSS/JS after the body tag on the site.
*/
class BodyForm extends ConfigFormBase { class BodyForm extends ConfigFormBase {
/** /**
* Implements FormBuilder::getFormId * Implements FormBuilder::getFormId.
*/ */
public function getFormId() { public function getFormId() {
return 'hfs_body_settings'; return 'hfs_body_settings';
} }
/** /**
* Implements ConfigFormBase::getEditableConfigNames * Implements ConfigFormBase::getEditableConfigNames.
*/ */
protected function getEditableConfigNames() { protected function getEditableConfigNames() {
return ['hfs_body_scripts.settings']; return ['hfs_body_scripts.settings'];
} }
/** /**
* Implements FormBuilder::buildForm * Implements FormBuilder::buildForm.
*/ */
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) { public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$body_section = \Drupal::config('hfs_body_scripts.settings')->get(); $body_section = $this->config('hfs_body_scripts.settings')->get();
$form['hfs_body'] = array( $form['hfs_body'] = [
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Add Scripts and Styles in body'), '#title' => t('Add Scripts and Styles in body'),
'#description' => t('All the defined scripts and styles in this section would be added next to <strong>body</strong> tag.'), '#description' => t('All the defined scripts and styles in this section would be added next to <strong>body</strong> tag.'),
); ];
$form['hfs_body']['styles'] = array( $form['hfs_body']['styles'] = [
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Body Styles'), '#title' => $this->t('Body Styles'),
'#default_value' => isset($body_section['styles']) ? $body_section['styles'] : '', '#default_value' => isset($body_section['styles']) ? $body_section['styles'] : '',
'#description' => t('<p>You can add multiple <strong>stylesheets</strong> here with multiple ways, For example: </p><p>1. &lt;link type="text/css" rel="stylesheet" href="http://www.example.com/style.css" media="all" /&gt;</p><p> 2. &lt;link type="text/css" rel="stylesheet" href="/style.css" media="all" /&gt;</p><p> 3. &lt;style&gt;#header { color: grey; }&lt;/style&gt;</p>'), '#description' => $this->t('<p>You can add multiple <strong>stylesheets</strong> here with multiple ways, For example: </p><p>1. &lt;link type="text/css" rel="stylesheet" href="http://www.example.com/style.css" media="all" /&gt;</p><p> 2. &lt;link type="text/css" rel="stylesheet" href="/style.css" media="all" /&gt;</p><p> 3. &lt;style&gt;#header { color: grey; }&lt;/style&gt;</p>'),
'#rows' => 10, '#rows' => 10,
); ];
$form['hfs_body']['scripts'] = array( $form['hfs_body']['scripts'] = [
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Body Scripts'), '#title' => $this->t('Body Scripts'),
'#default_value' => isset($body_section['scripts']) ? $body_section['scripts'] : '', '#default_value' => isset($body_section['scripts']) ? $body_section['scripts'] : '',
'#description' => t('<p>On mostly sites, this section is used to add the <strong>Google Tag Manager</strong>. <strong>Like:</strong></p><p>1. &lt;!-- Google Tag Manager --&gt;&lt;noscript&gt;<strong>Write Your code here</strong>&lt;/script&gt;&lt;!-- End Google Tag Manager --&gt;</p><p>You can also add multiple <strong>scripts</strong> here with multiple ways, For example: </p><p>1. &lt;script type="text/javascript" src="http://www.example.com/script.js"&gt;&lt;/script&gt;</p><p> 2. &lt;script type="text/javascript" src="/script.js"&gt;&lt;/script&gt;</p><p> 3. &lt;script type="text/javascript"&gt;console.log("HFS Body");&lt;/script&gt;</p>'), '#description' => $this->t('<p>On mostly sites, this section is used to add the <strong>Google Tag Manager</strong>. <strong>Like:</strong></p><p>1. &lt;!-- Google Tag Manager --&gt;&lt;noscript&gt;<strong>Write Your code here</strong>&lt;/script&gt;&lt;!-- End Google Tag Manager --&gt;</p><p>You can also add multiple <strong>scripts</strong> here with multiple ways, For example: </p><p>1. &lt;script type="text/javascript" src="http://www.example.com/script.js"&gt;&lt;/script&gt;</p><p> 2. &lt;script type="text/javascript" src="/script.js"&gt;&lt;/script&gt;</p><p> 3. &lt;script type="text/javascript"&gt;console.log("HFS Body");&lt;/script&gt;</p>'),
'#rows' => 10, '#rows' => 10,
); ];
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
} }
@ -60,11 +64,13 @@ class BodyForm extends ConfigFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues(); $values = $form_state->getValues();
\Drupal::service('config.factory')->getEditable('hfs_body_scripts.settings') $this->configFactory()
->getEditable('hfs_body_scripts.settings')
->set('styles', $values['styles']) ->set('styles', $values['styles'])
->set('scripts', $values['scripts']) ->set('scripts', $values['scripts'])
->save(); ->save();
drupal_set_message($this->t('Your Settings have been saved.'), 'status'); drupal_set_message($this->t('Your Settings have been saved.'), 'status');
} }
} }

View File

@ -6,48 +6,52 @@ use Drupal\Core\Form\ConfigFormBase;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
/**
* This Class Provides the settings page for adding CSS/JS before the end of body tag on the site.
*/
class FooterForm extends ConfigFormBase { class FooterForm extends ConfigFormBase {
/** /**
* Implements FormBuilder::getFormId * Implements FormBuilder::getFormId.
*/ */
public function getFormId() { public function getFormId() {
return 'hfs_footer_settings'; return 'hfs_footer_settings';
} }
/** /**
* Implements ConfigFormBase::getEditableConfigNames * Implements ConfigFormBase::getEditableConfigNames.
*/ */
protected function getEditableConfigNames() { protected function getEditableConfigNames() {
return ['hfs_footer_scripts.settings']; return ['hfs_footer_scripts.settings'];
} }
/** /**
* Implements FormBuilder::buildForm * Implements FormBuilder::buildForm.
*/ */
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) { public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$footer_section = \Drupal::config('hfs_footer_scripts.settings')->get(); $footer_section = $this->config('hfs_footer_scripts.settings')->get();
$form['hfs_footer'] = array( $form['hfs_footer'] = [
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Add Scripts and Styles in Footer'), '#title' => $this->t('Add Scripts and Styles in Footer'),
'#description' => t('All the defined scripts and styles in this section would be added just before closing the <strong>body</strong> tag.'), '#description' => $this->t('All the defined scripts and styles in this section would be added just before closing the <strong>body</strong> tag.'),
); ];
$form['hfs_footer']['styles'] = array( $form['hfs_footer']['styles'] = [
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Footer Styles'), '#title' => $this->t('Footer Styles'),
'#default_value' => isset($footer_section['styles']) ? $footer_section['styles'] : '', '#default_value' => isset($footer_section['styles']) ? $footer_section['styles'] : '',
'#description' => t('<p>You can add multiple <strong>stylesheets</strong> here with multiple ways, For example: </p><p>1. &lt;link type="text/css" rel="stylesheet" href="http://www.example.com/style.css" media="all" /&gt;</p><p> 2. &lt;link type="text/css" rel="stylesheet" href="/style.css" media="all" /&gt;</p><p> 3. &lt;style&gt;#header { color: grey; }&lt;/style&gt;</p>'), '#description' => $this->t('<p>You can add multiple <strong>stylesheets</strong> here with multiple ways, For example: </p><p>1. &lt;link type="text/css" rel="stylesheet" href="http://www.example.com/style.css" media="all" /&gt;</p><p> 2. &lt;link type="text/css" rel="stylesheet" href="/style.css" media="all" /&gt;</p><p> 3. &lt;style&gt;#header { color: grey; }&lt;/style&gt;</p>'),
'#rows' => 10, '#rows' => 10,
); ];
$form['hfs_footer']['scripts'] = array( $form['hfs_footer']['scripts'] = [
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Footer Scripts'), '#title' => $this->t('Footer Scripts'),
'#default_value' => isset($footer_section['scripts']) ? $footer_section['scripts'] : '', '#default_value' => isset($footer_section['scripts']) ? $footer_section['scripts'] : '',
'#description' => t('<p>You can add multiple <strong>scripts</strong> here with multiple ways, For example: </p><p>1. &lt;script type="text/javascript" src="http://www.example.com/script.js"&gt;&lt;/script&gt;</p><p> 2. &lt;script type="text/javascript" src="/script.js"&gt;&lt;/script&gt;</p><p> 3. &lt;script type="text/javascript"&gt;console.log("HFS Footer");&lt;/script&gt;</p>'), '#description' => $this->t('<p>You can add multiple <strong>scripts</strong> here with multiple ways, For example: </p><p>1. &lt;script type="text/javascript" src="http://www.example.com/script.js"&gt;&lt;/script&gt;</p><p> 2. &lt;script type="text/javascript" src="/script.js"&gt;&lt;/script&gt;</p><p> 3. &lt;script type="text/javascript"&gt;console.log("HFS Footer");&lt;/script&gt;</p>'),
'#rows' => 10, '#rows' => 10,
); ];
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
} }
@ -60,11 +64,13 @@ class FooterForm extends ConfigFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues(); $values = $form_state->getValues();
\Drupal::service('config.factory')->getEditable('hfs_footer_scripts.settings') $this->configFactory()
->getEditable('hfs_footer_scripts.settings')
->set('styles', $values['styles']) ->set('styles', $values['styles'])
->set('scripts', $values['scripts']) ->set('scripts', $values['scripts'])
->save(); ->save();
drupal_set_message($this->t('Your Settings have been saved.'), 'status'); drupal_set_message($this->t('Your Settings have been saved.'), 'status');
} }
} }