Same name in other branches
  1. 6.0.x advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm
  2. 8.x-2.x advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm
  3. 8.x-3.x advagg_validator/src/Form/CssLintForm.php \Drupal\advagg_validator\Form\CssLintForm
  4. 8.x-4.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

Expanded class hierarchy of CssLintForm

1 file declares its use of CssLintForm
CssLintFormTest.php dans advagg_validator/tests/src/Kernel/Form/CssLintFormTest.php
1 string reference to 'CssLintForm'
advagg_validator.routing.yml dans advagg_validator/advagg_validator.routing.yml
advagg_validator/advagg_validator.routing.yml

Fichier

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

Namespace

Drupal\advagg_validator\Form
View 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

Titre Trier par ordre décroissant Modifiers Object type Résumé 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