diff --git a/README.txt b/README.txt index cdc85a4..2db130a 100644 --- a/README.txt +++ b/README.txt @@ -4,17 +4,17 @@ from the front-end. You don't need to open any file for this purpose. INSTALLATION INSTRUCTIONS ------------------------- -1. Copy the files included in the tarball into a directory named "header_and_footer_scripts" in - your Drupal modules/ directory. -2. Login as site administrator. -3. Enable the HFS (Header Footer Scripts) module on the Administer -> Modules - page. -4. Add styles and scripts in settings on the Administer -> Configuration -> - Development -> HFS (Header Footer Scripts) Page. -5. Enjoy. +1. Copy the files included in the tarball into a directory named + "header_and_footer_scripts" in your Drupal modules/ directory. +2. Login as site administrator. +3. Enable the HFS (Header Footer Scripts) module on the + Administer -> Modules page. +4. Add styles and scripts in settings on the Administer -> + Configuration -> Development -> HFS (Header Footer Scripts) Page. +5. Enjoy. NOTES ----- -This module adds the styles and scripts on all over the site. There are 2 -setting pages. +This module adds the styles and scripts on all over the site. +There are 2 setting pages. These setting pages are allow you add the scripts in the desired region. diff --git a/header_and_footer_scripts.install b/header_and_footer_scripts.install index 52e2ea8..32a8802 100644 --- a/header_and_footer_scripts.install +++ b/header_and_footer_scripts.install @@ -9,6 +9,10 @@ * Implements hook_uninstall(). */ function header_and_footer_scripts_uninstall() { - \Drupal::service('config.factory')->getEditable('hfs_body_scripts.settings')->delete(); - \Drupal::service('config.factory')->getEditable('hfs_footer_scripts.settings')->delete(); + \Drupal::service('config.factory') + ->getEditable('hfs_body_scripts.settings') + ->delete(); + \Drupal::service('config.factory') + ->getEditable('hfs_footer_scripts.settings') + ->delete(); } diff --git a/header_and_footer_scripts.links.menu.yml b/header_and_footer_scripts.links.menu.yml index efd2177..542b6b0 100644 --- a/header_and_footer_scripts.links.menu.yml +++ b/header_and_footer_scripts.links.menu.yml @@ -2,4 +2,4 @@ hfs.admin.body_settings: title: 'HFS (Header Footer Scripts)' description: 'Allow to add scripts and styles from the frontend at the start of body tag.' parent: system.admin_config_development - route_name: hfs.admin.body_settings \ No newline at end of file + route_name: hfs.admin.body_settings diff --git a/header_and_footer_scripts.links.task.yml b/header_and_footer_scripts.links.task.yml index bdfb3eb..77710e1 100644 --- a/header_and_footer_scripts.links.task.yml +++ b/header_and_footer_scripts.links.task.yml @@ -5,4 +5,4 @@ hfs.admin.body_settings: hfs.admin.footer_settings: route_name: hfs.admin.footer_settings title: 'Footer Scripts' - base_route: hfs.admin.body_settings \ No newline at end of file + base_route: hfs.admin.body_settings diff --git a/header_and_footer_scripts.module b/header_and_footer_scripts.module index 3568cef..f53c1f7 100644 --- a/header_and_footer_scripts.module +++ b/header_and_footer_scripts.module @@ -2,38 +2,44 @@ /** * @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(). * - * 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) { - $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'])) { $output_styles = preg_split("/(<\/style>|\/>)/", $body_section['styles']); $i = 1; foreach ($output_styles as $row) { - if (empty($row)) continue; + if (empty($row)) { + continue; + } $style_tag = 'style'; $style_attr = ''; - $value = ''; + $value = ''; $style_attributes = preg_replace('/()/', $style_attributes, 2); - if (isset($get_style_attr[1])) + if (isset($get_style_attr[1])) { $value = $get_style_attr[1]; + } $get_style_tag = preg_split('/ 'html_tag', - '#tag' => $style_tag, - '#value' => $value + $page_top['top_styles_' . $i] = [ + '#type' => 'html_tag', + '#tag' => $style_tag, + '#value' => $value, ]; - if (is_array($style_attr)) - $page_top['top_styles_'.$i]['#attributes'] = $style_attr; + if (is_array($style_attr)) { + $page_top['top_styles_' . $i]['#attributes'] = $style_attr; + } $i++; } } @@ -66,22 +76,26 @@ function header_and_footer_scripts_page_top(array &$page_top) { $i = 1; foreach ($output_scripts as $row) { - if (empty($row)) continue; + if (empty($row)) { + continue; + } $script_tag = 'script'; $script_attr = ''; $value = ''; - + $script_attributes = preg_replace('/()/', $script_attributes, 2); - if (isset($get_script_attr[1])) + if (isset($get_script_attr[1])) { $value = $get_script_attr[1]; + } $get_script_tag = preg_split('/