You are here

public function CssLintForm::buildForm in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm::buildForm()
  2. 8.2 advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

advagg_validator/src/Form/CssLintForm.php, line 22

Class

CssLintForm
Configure form for CSSHint validation of CSS files.

Namespace

Drupal\advagg_validator\Form

Code

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;
}