You are here

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

Same name and namespace in other branches
  1. 8.4 advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm::buildForm()
  2. 8.3 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');
  if (file_exists(DRUPAL_ROOT . '/.csslintrc')) {
    $json_string = file_get_contents(DRUPAL_ROOT . '/.csslintrc');
    if (!empty($json_string)) {
      $json_data = json_decode($json_string, TRUE);
    }
  }
  $form['#attached']['library'][] = 'advagg_validator/csslint';
  if (!empty($json_data)) {
    $form['#attached']['drupalSettings']['csslint'] = [
      'rules' => $json_data,
    ];
  }
  $form = parent::buildForm($form, $form_state);
  unset($form['actions']);
  return $form;
}