Change prefix with the module name to avoid conflicts

This commit is contained in:
samiahmedsiddiqui 2018-10-08 18:44:50 +05:00
parent d5b078b3f9
commit b94d2b1c72
10 changed files with 83 additions and 42 deletions

View File

@ -1,7 +1,7 @@
INTRODUCTION
------------
HFS (Header Footer Scripts) module for Drupal 8.x.
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.
@ -26,13 +26,13 @@ CONFIGURATION
* Configure user permissions in Administration » People » Permissions
- Access HFS (Header Footer Scripts)
- Access 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.
Configuration -> Development -> Header Footer Scripts Page.
MAINTAINERS
-----------

View File

@ -1,8 +1,8 @@
name: HFS (Header Footer Scripts)
name: Header and 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
configure: header_and_footer_scripts.admin.header

View File

@ -9,13 +9,54 @@
* Implements hook_uninstall().
*/
function header_and_footer_scripts_uninstall() {
\Drupal::service('config.factory')
->getEditable('header_and_footer_scripts.header.settings')
->delete();
\Drupal::service('config.factory')
->getEditable('header_and_footer_scripts.body.settings')
->delete();
\Drupal::service('config.factory')
->getEditable('header_and_footer_scripts.footer.settings')
->delete();
}
/**
* Implements hook_update_N().
*
* Adding new configuration variables and updating current configuration
* in it to avoid conflict with any other module.
*/
function header_and_footer_scripts_update_8201() {
$body_section = \Drupal::config('hfs_body_scripts.settings')->get();
$footer_section = \Drupal::config('hfs_footer_scripts.settings')->get();
if (isset($body_section['styles'])) {
\Drupal::configFactory()
->getEditable('header_and_footer_scripts.body.settings')
->set('styles', $body_section['styles'])
->save();
}
if (isset($body_section['scripts'])) {
\Drupal::configFactory()
->getEditable('header_and_footer_scripts.body.settings')
->set('scripts', $body_section['scripts'])
->save();
}
\Drupal::service('config.factory')
->getEditable('hfs_body_scripts.settings')
->delete();
if (isset($footer_section['styles'])) {
\Drupal::configFactory()
->getEditable('header_and_footer_scripts.footer.settings')
->set('styles', $footer_section['styles'])
->save();
}
if (isset($footer_section['scripts'])) {
\Drupal::configFactory()
->getEditable('header_and_footer_scripts.footer.settings')
->set('scripts', $footer_section['scripts'])
->save();
}
\Drupal::service('config.factory')
->getEditable('hfs_footer_scripts.settings')
->delete();
\Drupal::service('config.factory')
->getEditable('hfs_header_scripts.settings')
->delete();
}

View File

@ -1,5 +1,5 @@
hfs.admin.body_settings:
title: 'HFS (Header Footer Scripts)'
header_and_footer_scripts.admin.header:
title: '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.header_settings
route_name: header_and_footer_scripts.admin.header

View File

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

View File

@ -16,7 +16,7 @@ function header_and_footer_scripts_help($route_name, RouteMatchInterface $route_
$output = '<h2>' . t('About') . '</h2>';
$output .= '<p>' . t('This module allows you to add style and scripts in your site or , You do not 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>';
$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 -> Header Footer Scripts') . '</p>';
return $output;
}
@ -29,7 +29,7 @@ function header_and_footer_scripts_help($route_name, RouteMatchInterface $route_
* 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('header_and_footer_scripts.body.settings')->get();
if (isset($body_section['styles']) && !empty($body_section['styles'])) {
$output_styles = preg_split("/(<\/style>|\/>)/", $body_section['styles']);
$i = 1;
@ -155,7 +155,7 @@ function header_and_footer_scripts_page_top(array &$page_top) {
* which are defined on the settings page.
*/
function header_and_footer_scripts_page_bottom(array &$page_bottom) {
$footer_section = \Drupal::config('hfs_footer_scripts.settings')->get();
$footer_section = \Drupal::config('header_and_footer_scripts.footer.settings')->get();
if (isset($footer_section['styles']) && !empty($footer_section['styles'])) {
$output_styles = preg_split("/(<\/style>|\/>)/", $footer_section['styles']);
$i = 1;
@ -281,7 +281,7 @@ function header_and_footer_scripts_page_bottom(array &$page_bottom) {
* which are defined on the settings page.
*/
function header_and_footer_scripts_page_attachments_alter(array &$attachments) {
$header_section = \Drupal::config('hfs_header_scripts.settings')->get();
$header_section = \Drupal::config('header_and_footer_scripts.header.settings')->get();
if (isset($header_section['styles']) && !empty($header_section['styles'])) {
$output_styles = preg_split("/(<\/style>|\/>)/", $header_section['styles']);
$i = 1;

View File

@ -1,21 +1,21 @@
hfs.admin.header_settings:
path: '/admin/config/development/hfs/header'
header_and_footer_scripts.admin.header:
path: '/admin/config/development/header-and-footer-scripts/header'
defaults:
_form: '\Drupal\header_and_footer_scripts\Form\HeaderForm'
_title: 'HFS (Header Footer Scripts)'
_title: 'Header Footer Scripts Settings for head'
requirements:
_permission: 'header_and_footer_scripts_settings'
hfs.admin.body_settings:
path: '/admin/config/development/hfs/body'
header_and_footer_scripts.admin.body:
path: '/admin/config/development/header-and-footer-scripts/body'
defaults:
_form: '\Drupal\header_and_footer_scripts\Form\BodyForm'
_title: 'HFS (Header Footer Scripts) for Body'
_title: 'Header and Footer Scripts Settings for Body'
requirements:
_permission: 'header_and_footer_scripts_settings'
hfs.admin.footer_settings:
path: '/admin/config/development/hfs/footer'
header_and_footer_scripts.admin.footer:
path: '/admin/config/development/header-and-footer-scripts/footer'
defaults:
_form: '\Drupal\header_and_footer_scripts\Form\FooterForm'
_title: 'HFS (Header Footer Scripts) for Footer'
_title: 'Header and Footer Scripts Settings for Footer'
requirements:
_permission: 'header_and_footer_scripts_settings'

View File

@ -22,14 +22,14 @@ class BodyForm extends ConfigFormBase {
* Implements ConfigFormBase::getEditableConfigNames.
*/
protected function getEditableConfigNames() {
return ['hfs_body_scripts.settings'];
return ['header_and_footer_scripts.body.settings'];
}
/**
* Implements FormBuilder::buildForm.
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$body_section = $this->config('hfs_body_scripts.settings')->get();
$body_section = $this->config('header_and_footer_scripts.body.settings')->get();
$form['hfs_body'] = [
'#type' => 'fieldset',
@ -65,7 +65,7 @@ class BodyForm extends ConfigFormBase {
$values = $form_state->getValues();
$this->configFactory()
->getEditable('hfs_body_scripts.settings')
->getEditable('header_and_footer_scripts.body.settings')
->set('styles', $values['styles'])
->set('scripts', $values['scripts'])
->save();

View File

@ -22,14 +22,14 @@ class FooterForm extends ConfigFormBase {
* Implements ConfigFormBase::getEditableConfigNames.
*/
protected function getEditableConfigNames() {
return ['hfs_footer_scripts.settings'];
return ['header_and_footer_scripts.footer.settings'];
}
/**
* Implements FormBuilder::buildForm.
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$footer_section = $this->config('hfs_footer_scripts.settings')->get();
$footer_section = $this->config('header_and_footer_scripts.footer.settings')->get();
$form['hfs_footer'] = [
'#type' => 'fieldset',
@ -65,7 +65,7 @@ class FooterForm extends ConfigFormBase {
$values = $form_state->getValues();
$this->configFactory()
->getEditable('hfs_footer_scripts.settings')
->getEditable('header_and_footer_scripts.footer.settings')
->set('styles', $values['styles'])
->set('scripts', $values['scripts'])
->save();

View File

@ -22,14 +22,14 @@ class HeaderForm extends ConfigFormBase {
* Implements ConfigFormBase::getEditableConfigNames.
*/
protected function getEditableConfigNames() {
return ['hfs_header_scripts.settings'];
return ['header_and_footer_scripts.header.settings'];
}
/**
* Implements FormBuilder::buildForm.
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$header_section = $this->config('hfs_header_scripts.settings')->get();
$header_section = $this->config('header_and_footer_scripts.header.settings')->get();
$form['hfs_header'] = [
'#type' => 'fieldset',
@ -65,7 +65,7 @@ class HeaderForm extends ConfigFormBase {
$values = $form_state->getValues();
$this->configFactory()
->getEditable('hfs_header_scripts.settings')
->getEditable('header_and_footer_scripts.header.settings')
->set('styles', $values['styles'])
->set('scripts', $values['scripts'])
->save();