diff --git a/README.txt b/README.txt index c8efa81..c9b7f87 100755 --- a/README.txt +++ b/README.txt @@ -1,20 +1,48 @@ +INTRODUCTION +------------ + 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 - "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 3 -setting pages. -These setting pages are allow you add the scripts in the desired region. +setting pages. These setting pages are allow you add the scripts +in the desired region. + +REQUIREMENTS +------------ + +No special requirements. + +INSTALLATION +------------ + + * Install as you would normally install a contributed Drupal module. Visit: + https://www.drupal.org/docs/8/extending-drupal-8/installing-drupal-8-modules + for further information. + +CONFIGURATION +------------- + + * Configure user permissions in Administration » People » Permissions + + - Access HFS (Header Footer Scripts) + + Users in roles with "Add Scripts all over the site" permission will + add / remove the styles and scripts from any position. + + * Add styles and scripts in settings on the Administer -> + Configuration -> Development -> HFS (Header Footer Scripts) Page. + +MAINTAINERS +----------- + +Current maintainers: + * Aliya Yasir (aliyayasir) - https://www.drupal.org/user/213804 + * Sami Ahmed Siddiqui (sasiddiqui) - https://www.drupal.org/user/3100375 + +This project has been sponsored by: + * YAS Global + Leading Web and App Development company, which helps businesses to grow + online using advanced platforms. It works on Drupal, WordPress, .Net and + Mobile Apps. Visit https://www.yasglobal.com for more information. diff --git a/header_and_footer_scripts.links.menu.yml b/header_and_footer_scripts.links.menu.yml index 542b6b0..cb563f5 100755 --- 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 + route_name: hfs.admin.header_settings diff --git a/header_and_footer_scripts.links.task.yml b/header_and_footer_scripts.links.task.yml index f1f24ea..107a968 100755 --- a/header_and_footer_scripts.links.task.yml +++ b/header_and_footer_scripts.links.task.yml @@ -1,12 +1,12 @@ hfs.admin.header_settings: route_name: hfs.admin.header_settings title: 'Header Scripts' - base_route: hfs.admin.body_settings + base_route: hfs.admin.header_settings hfs.admin.body_settings: route_name: hfs.admin.body_settings title: 'Body Scripts' - base_route: hfs.admin.body_settings + base_route: hfs.admin.header_settings hfs.admin.footer_settings: route_name: hfs.admin.footer_settings title: 'Footer Scripts' - base_route: hfs.admin.body_settings + base_route: hfs.admin.header_settings diff --git a/header_and_footer_scripts.module b/header_and_footer_scripts.module index fea7805..9703b99 100755 --- a/header_and_footer_scripts.module +++ b/header_and_footer_scripts.module @@ -5,6 +5,22 @@ * Add scripts and styles from the frontend on all over the site. */ +/** + * Implements hook_help(). + */ +function header_and_footer_scripts_help($route_name, +\Drupal\Core\Routing\RouteMatchInterface $route_match) { + switch ($route_name) { + case 'help.page.header_and_footer_scripts': + $output = '
' . t('This module allows you to add style and scripts in your site or , You don\'t need to open any file for this purpose.') . '
'; + $output .= '' . t('Header and Footer Scripts provides you the capability to quickly add the style and scripts in your site. It provides you 3 regions (Header, Body, and Footer) of the page on which you can add the style and script. You can add custom style/script file, add Google or other Analytics code, inline css, inline js and so on. You can configure them from the Administer -> Configuration -> Development -> HFS (Header Footer Scripts)') . '
'; + + return $output; + } +} + /** * Implements hook_page_top(). * @@ -268,7 +284,7 @@ function header_and_footer_scripts_page_attachments_alter(array &$attachments) { if (isset($header_section['styles']) && !empty($header_section['styles'])) { $output_styles = preg_split("/(<\/style>|\/>)/", $header_section['styles']); $i = 1; - $i = count($attachments['#attached']['html_head']) + 1; + $i = count($attachments['#attached']['html_head']) + 1; foreach ($output_styles as $row) { if (empty($row)) { continue; @@ -312,23 +328,23 @@ function header_and_footer_scripts_page_attachments_alter(array &$attachments) { } } - $attachments['#attached']['html_head'][$i][0] = array( + $attachments['#attached']['html_head'][$i][0] = [ '#type' => 'html_tag', '#tag' => $style_tag, - '#value' => $value - ); + '#value' => $value, + ]; if (is_array($style_attr)) { $attachments['#attached']['html_head'][$i][0]['#attributes'] = $style_attr; } - $attachments['#attached']['html_head'][$i][1] = 'header-and-footer-css-' . $i; - + $attachments['#attached']['html_head'][$i][1] = 'header-and-footer-css-' . $i; + $i++; } } if (isset($header_section['scripts']) && !empty($header_section['scripts'])) { $output_scripts = preg_split("/(<\/script>|<\/noscript>)/", $header_section['scripts']); $i = 1; - $i = count($attachments['#attached']['html_head']) +1; + $i = count($attachments['#attached']['html_head']) + 1; foreach ($output_scripts as $row) { if (empty($row)) { @@ -373,14 +389,14 @@ function header_and_footer_scripts_page_attachments_alter(array &$attachments) { } } - $attachments['#attached']['html_head'][$i] = array( - array( + $attachments['#attached']['html_head'][$i] = [ + [ '#type' => 'html_tag', '#tag' => $script_tag, '#value' => $value, - ), - 'header-and-footer-scripts-' . $i - ); + ], + 'header-and-footer-scripts-' . $i, + ]; if (is_array($script_attr)) { $attachments['#attached']['html_head'][$i][0]['#attributes'] = $script_attr; }