Fix Drupal 8 Coding Standards

This commit is contained in:
samiahmedsiddiqui
2017-09-18 11:41:56 +05:00
parent 80fb9de84f
commit 98161a6384
9 changed files with 166 additions and 117 deletions

View File

@@ -6,48 +6,52 @@ use Drupal\Core\Form\ConfigFormBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormStateInterface;
/**
* This Class Provides the settings page for adding CSS/JS before the end of body tag on the site.
*/
class FooterForm extends ConfigFormBase {
/**
* Implements FormBuilder::getFormId
* Implements FormBuilder::getFormId.
*/
public function getFormId() {
return 'hfs_footer_settings';
}
/**
* Implements ConfigFormBase::getEditableConfigNames
* Implements ConfigFormBase::getEditableConfigNames.
*/
protected function getEditableConfigNames() {
return ['hfs_footer_scripts.settings'];
}
/**
* Implements FormBuilder::buildForm
* Implements FormBuilder::buildForm.
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$footer_section = \Drupal::config('hfs_footer_scripts.settings')->get();
$footer_section = $this->config('hfs_footer_scripts.settings')->get();
$form['hfs_footer'] = array(
$form['hfs_footer'] = [
'#type' => 'fieldset',
'#title' => t('Add Scripts and Styles in Footer'),
'#description' => t('All the defined scripts and styles in this section would be added just before closing the <strong>body</strong> tag.'),
);
'#title' => $this->t('Add Scripts and Styles in Footer'),
'#description' => $this->t('All the defined scripts and styles in this section would be added just before closing the <strong>body</strong> tag.'),
];
$form['hfs_footer']['styles'] = array(
$form['hfs_footer']['styles'] = [
'#type' => 'textarea',
'#title' => t('Footer Styles'),
'#title' => $this->t('Footer Styles'),
'#default_value' => isset($footer_section['styles']) ? $footer_section['styles'] : '',
'#description' => t('<p>You can add multiple <strong>stylesheets</strong> here with multiple ways, For example: </p><p>1. &lt;link type="text/css" rel="stylesheet" href="http://www.example.com/style.css" media="all" /&gt;</p><p> 2. &lt;link type="text/css" rel="stylesheet" href="/style.css" media="all" /&gt;</p><p> 3. &lt;style&gt;#header { color: grey; }&lt;/style&gt;</p>'),
'#description' => $this->t('<p>You can add multiple <strong>stylesheets</strong> here with multiple ways, For example: </p><p>1. &lt;link type="text/css" rel="stylesheet" href="http://www.example.com/style.css" media="all" /&gt;</p><p> 2. &lt;link type="text/css" rel="stylesheet" href="/style.css" media="all" /&gt;</p><p> 3. &lt;style&gt;#header { color: grey; }&lt;/style&gt;</p>'),
'#rows' => 10,
);
];
$form['hfs_footer']['scripts'] = array(
$form['hfs_footer']['scripts'] = [
'#type' => 'textarea',
'#title' => t('Footer Scripts'),
'#title' => $this->t('Footer Scripts'),
'#default_value' => isset($footer_section['scripts']) ? $footer_section['scripts'] : '',
'#description' => t('<p>You can add multiple <strong>scripts</strong> here with multiple ways, For example: </p><p>1. &lt;script type="text/javascript" src="http://www.example.com/script.js"&gt;&lt;/script&gt;</p><p> 2. &lt;script type="text/javascript" src="/script.js"&gt;&lt;/script&gt;</p><p> 3. &lt;script type="text/javascript"&gt;console.log("HFS Footer");&lt;/script&gt;</p>'),
'#description' => $this->t('<p>You can add multiple <strong>scripts</strong> here with multiple ways, For example: </p><p>1. &lt;script type="text/javascript" src="http://www.example.com/script.js"&gt;&lt;/script&gt;</p><p> 2. &lt;script type="text/javascript" src="/script.js"&gt;&lt;/script&gt;</p><p> 3. &lt;script type="text/javascript"&gt;console.log("HFS Footer");&lt;/script&gt;</p>'),
'#rows' => 10,
);
];
return parent::buildForm($form, $form_state);
}
@@ -60,11 +64,13 @@ class FooterForm extends ConfigFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
\Drupal::service('config.factory')->getEditable('hfs_footer_scripts.settings')
$this->configFactory()
->getEditable('hfs_footer_scripts.settings')
->set('styles', $values['styles'])
->set('scripts', $values['scripts'])
->save();
drupal_set_message($this->t('Your Settings have been saved.'), 'status');
}
}