Same name in other branches
- 5.0.x advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm
- 6.0.x advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm
- 8.x-2.x advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm
- 8.x-3.x advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm
Configure form for CSSHint validation of CSS files.
Hierarchy
- class \Drupal\advagg\Form\AdvaggFormBase extends \Drupal\Core\Form\ConfigFormBase
- class \Drupal\advagg_validator\Form\BaseValidatorForm extends \Drupal\advagg\Form\AdvaggFormBase
- class \Drupal\advagg_validator\Form\CssLintForm extends \Drupal\advagg_validator\Form\BaseValidatorForm
- class \Drupal\advagg_validator\Form\BaseValidatorForm extends \Drupal\advagg\Form\AdvaggFormBase
Expanded class hierarchy of CssLintForm
1 file declares its use of CssLintForm
- CssLintFormTest.php in advagg_validator/
tests/ src/ Kernel/ Form/ CssLintFormTest.php
1 string reference to 'CssLintForm'
- advagg_validator.routing.yml in advagg_validator/
advagg_validator.routing.yml - advagg_validator/advagg_validator.routing.yml
File
-
advagg_validator/
src/ Form/ CssLintForm.php, line 10
Namespace
Drupal\advagg_validator\FormView source
class CssLintForm extends BaseValidatorForm {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'advagg_validator_csslint';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::generateForm('css');
$rules = [];
if (file_exists(DRUPAL_ROOT . '/.csslintrc')) {
$rule_string = file_get_contents(DRUPAL_ROOT . '/.csslintrc');
if (empty($rule_string)) {
}
elseif (substr($rule_string, 0, 1) === '{') {
$rules = json_decode($rule_string, TRUE);
}
elseif (substr($rule_string, 0, 1) === '-') {
$rules = $this->decodeRules($rule_string);
}
}
$form['#attached']['library'][] = 'advagg_validator/csslint';
$form['#attached']['drupalSettings']['csslint'] = [
'rules' => $rules,
];
$form = parent::buildForm($form, $form_state);
unset($form['actions']);
return $form;
}
/**
* Decode a .csslintrc file to rules array.
*
* @param string $rule_string
* The raw rule string.
*
* @return array
* The rules array.
*/
protected function decodeRules($rule_string) {
$values = [
'errors' => 2,
'warning' => 1,
'ignore' => 0,
'exclude-list' => 1,
];
$rules = [];
$group = '';
$raw = explode("\n", $rule_string);
foreach ($raw as $rule) {
if (empty($rule)) {
continue;
}
if (substr($rule, 0, 1) === '-') {
$split = explode('=', trim($rule, " \t\n\r\x00\v-,"));
$group = $split[0];
$rules[$group] = [];
if (isset($split[1])) {
$rules[$group][$split[1]] = $values[$group];
}
continue;
}
$rules[$group][trim($rule, " \t\n\r\x00\v,")] = $values[$group];
}
return $rules;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
AdvaggFormBase::isAjax | protected | function | Checks if the form was submitted by AJAX. | ||
BaseValidatorForm::$streamWrapperManager | protected | property | The StreamWrapper manage. | ||
BaseValidatorForm::create | public static | function | Overrides AdvaggFormBase::create | 1 | |
BaseValidatorForm::domExtractor | protected | function | Extract info from the DOMNode Object. | ||
BaseValidatorForm::generateForm | public | function | Generate a hierarchical form sorted by path from asset files. | ||
BaseValidatorForm::getEditableConfigNames | protected | function | |||
BaseValidatorForm::getElement | protected | function | Get array element that corresponds to directory. | ||
BaseValidatorForm::hideGoodFiles | protected | function | Do not display info on a file if it is valid. | ||
BaseValidatorForm::scanAllDirs | protected | function | Recursively scan the drupal webroot for files matching the given extension. | ||
BaseValidatorForm::scanDirectory | protected | function | Finds all files that match a given mask in a given directory. | ||
BaseValidatorForm::testFiles | protected | function | Perform server side test(s) on all given files. | 1 | |
CssLintForm::buildForm | public | function | |||
CssLintForm::decodeRules | protected | function | Decode a .csslintrc file to rules array. | ||
CssLintForm::getFormId | public | function |