Updated README.txt, implemented hook_help, and fixed coding standard issues

This commit is contained in:
samiahmedsiddiqui 2018-10-08 17:04:21 +05:00
parent eac6f1730f
commit 912591d36e
4 changed files with 75 additions and 31 deletions

View File

@ -1,20 +1,48 @@
INTRODUCTION
------------
HFS (Header Footer Scripts) module for Drupal 8.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 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. 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 This module adds the styles and scripts on all over the site. There are 3
setting pages. setting pages. These setting pages are allow you add the scripts
These setting pages are allow you add the scripts in the desired region. 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.

View File

@ -2,4 +2,4 @@ hfs.admin.body_settings:
title: 'HFS (Header Footer Scripts)' title: 'HFS (Header Footer Scripts)'
description: 'Allow to add scripts and styles from the frontend at the start of body tag.' description: 'Allow to add scripts and styles from the frontend at the start of body tag.'
parent: system.admin_config_development parent: system.admin_config_development
route_name: hfs.admin.body_settings route_name: hfs.admin.header_settings

View File

@ -1,12 +1,12 @@
hfs.admin.header_settings: hfs.admin.header_settings:
route_name: hfs.admin.header_settings route_name: hfs.admin.header_settings
title: 'Header Scripts' title: 'Header Scripts'
base_route: hfs.admin.body_settings base_route: hfs.admin.header_settings
hfs.admin.body_settings: hfs.admin.body_settings:
route_name: hfs.admin.body_settings route_name: hfs.admin.body_settings
title: 'Body Scripts' title: 'Body Scripts'
base_route: hfs.admin.body_settings base_route: hfs.admin.header_settings
hfs.admin.footer_settings: hfs.admin.footer_settings:
route_name: hfs.admin.footer_settings route_name: hfs.admin.footer_settings
title: 'Footer Scripts' title: 'Footer Scripts'
base_route: hfs.admin.body_settings base_route: hfs.admin.header_settings

View File

@ -5,6 +5,22 @@
* Add scripts and styles from the frontend on all over the site. * 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 = '<h2>' . t('About') . '</h2>';
$output .= '<p>' . 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.') . '</p>';
$output .= '<h2>' . t('Uses') . '</h2>';
$output .= '<p>' . 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)') . '</p>';
return $output;
}
}
/** /**
* Implements hook_page_top(). * 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'])) { if (isset($header_section['styles']) && !empty($header_section['styles'])) {
$output_styles = preg_split("/(<\/style>|\/>)/", $header_section['styles']); $output_styles = preg_split("/(<\/style>|\/>)/", $header_section['styles']);
$i = 1; $i = 1;
$i = count($attachments['#attached']['html_head']) + 1; $i = count($attachments['#attached']['html_head']) + 1;
foreach ($output_styles as $row) { foreach ($output_styles as $row) {
if (empty($row)) { if (empty($row)) {
continue; 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', '#type' => 'html_tag',
'#tag' => $style_tag, '#tag' => $style_tag,
'#value' => $value '#value' => $value,
); ];
if (is_array($style_attr)) { if (is_array($style_attr)) {
$attachments['#attached']['html_head'][$i][0]['#attributes'] = $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++; $i++;
} }
} }
if (isset($header_section['scripts']) && !empty($header_section['scripts'])) { if (isset($header_section['scripts']) && !empty($header_section['scripts'])) {
$output_scripts = preg_split("/(<\/script>|<\/noscript>)/", $header_section['scripts']); $output_scripts = preg_split("/(<\/script>|<\/noscript>)/", $header_section['scripts']);
$i = 1; $i = 1;
$i = count($attachments['#attached']['html_head']) +1; $i = count($attachments['#attached']['html_head']) + 1;
foreach ($output_scripts as $row) { foreach ($output_scripts as $row) {
if (empty($row)) { if (empty($row)) {
@ -373,14 +389,14 @@ function header_and_footer_scripts_page_attachments_alter(array &$attachments) {
} }
} }
$attachments['#attached']['html_head'][$i] = array( $attachments['#attached']['html_head'][$i] = [
array( [
'#type' => 'html_tag', '#type' => 'html_tag',
'#tag' => $script_tag, '#tag' => $script_tag,
'#value' => $value, '#value' => $value,
), ],
'header-and-footer-scripts-' . $i 'header-and-footer-scripts-' . $i,
); ];
if (is_array($script_attr)) { if (is_array($script_attr)) {
$attachments['#attached']['html_head'][$i][0]['#attributes'] = $script_attr; $attachments['#attached']['html_head'][$i][0]['#attributes'] = $script_attr;
} }