diff --git a/README.txt b/README.txt index b24a38b..cdc85a4 100644 --- a/README.txt +++ b/README.txt @@ -1,11 +1,11 @@ -HFS (Header Footer Scripts) module for Drupal 7.x. +HFS (Header Footer Scripts) module for Drupal 8.x. This module allows you to add style and scripts in different region of the page 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 "hfs" in - your Drupal sites/all/modules/ directory. +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. @@ -15,6 +15,6 @@ INSTALLATION INSTRUCTIONS NOTES ----- -This module adds the styles and scripts on all over the site. There are 3 +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.info.yml b/header_and_footer_scripts.info.yml new file mode 100644 index 0000000..dba634a --- /dev/null +++ b/header_and_footer_scripts.info.yml @@ -0,0 +1,8 @@ +name: HFS (Header Footer Scripts) +description: This plugin allows you to add the scripts and styles on overall site from the front-end. No need to open files and add them there. +package: HFS + +type: module +core: 8.x + +configure: hfs.admin.body_settings diff --git a/header_and_footer_scripts.install b/header_and_footer_scripts.install new file mode 100644 index 0000000..52e2ea8 --- /dev/null +++ b/header_and_footer_scripts.install @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..efd2177 --- /dev/null +++ b/header_and_footer_scripts.links.menu.yml @@ -0,0 +1,5 @@ +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 diff --git a/header_and_footer_scripts.links.task.yml b/header_and_footer_scripts.links.task.yml new file mode 100644 index 0000000..bdfb3eb --- /dev/null +++ b/header_and_footer_scripts.links.task.yml @@ -0,0 +1,8 @@ +hfs.admin.body_settings: + route_name: hfs.admin.body_settings + title: 'Body Scripts' + base_route: 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 diff --git a/header_and_footer_scripts.module b/header_and_footer_scripts.module new file mode 100644 index 0000000..3568cef --- /dev/null +++ b/header_and_footer_scripts.module @@ -0,0 +1,220 @@ +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; + + $style_tag = 'style'; + $style_attr = ''; + $value = ''; + + $style_attributes = preg_replace('/()/', $style_attributes, 2); + + if (isset($get_style_attr[1])) + $value = $get_style_attr[1]; + + $get_style_tag = preg_split('/ 'html_tag', + '#tag' => $style_tag, + '#value' => $value + ]; + if (is_array($style_attr)) + $page_top['top_styles_'.$i]['#attributes'] = $style_attr; + $i++; + } + } + if (isset($body_section['scripts']) && !empty($body_section['scripts'])) { + $output_scripts = preg_split("/(<\/script>|<\/noscript>)/", $body_section['scripts']); + $i = 1; + foreach ($output_scripts as $row) { + + if (empty($row)) continue; + + $script_tag = 'script'; + $script_attr = ''; + $value = ''; + + $script_attributes = preg_replace('/()/', $script_attributes, 2); + + if (isset($get_script_attr[1])) + $value = $get_script_attr[1]; + + $get_script_tag = preg_split('/