You are here

public function SensorGitDirtyTree::settingsForm in Monitoring 7

Gets settings form for a specific sensor.

Parameters

$form: Drupal $form structure.

array $form_state: Drupal $form_state object. Carrying the string sensor_name.

Return value

array Drupal form structure.

Overrides SensorConfigurable::settingsForm

File

lib/Drupal/monitoring/Sensor/Sensors/SensorGitDirtyTree.php, line 282
Contains \Drupal\monitoring\Sensor\Sensors\SensorGitDirtyTree.

Class

SensorGitDirtyTree
Monitors the git repository for dirty files.

Namespace

Drupal\monitoring\Sensor\Sensors

Code

public function settingsForm($form, &$form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['repo_path'] = array(
    '#type' => 'textfield',
    '#default_value' => $this->info
      ->getSetting('repo_path'),
    '#title' => t('Repository path'),
    '#description' => t('Path to the Git repository relative to the Drupal root directory.'),
  );
  $branches = $this
    ->runCommand('branches_cmd', t('Failing to get Git branches, Git might not be available.'));
  $expected_branch = $this->info
    ->getSetting('expected_branch');
  if (empty($expected_branch)) {
    $expected_branch = $this
      ->runCommand('actual_branch_cmd', t('Failing to get the actual branch, Git might not be available.'));
  }
  $options = array();
  foreach ($branches as $branch) {
    $options[$branch] = $branch;
  }
  $form['check_branch'] = array(
    '#type' => 'checkbox',
    '#default_value' => $this->info
      ->getSetting('check_branch'),
    '#title' => t('Branch control'),
    '#description' => t('Check if the current branch is different from the selected.'),
    '#disabled' => !$options,
  );
  $form['expected_branch'] = array(
    '#type' => 'select',
    '#default_value' => $expected_branch,
    '#maxlength' => 255,
    '#empty_option' => t('- Select -'),
    '#options' => $options,
    '#title' => t('Expected active branch'),
    '#description' => t('The branch that is going to be checked out.'),
    '#states' => array(
      // Hide the branch selector when the check_branch checkbox is disabled.
      'invisible' => array(
        ':input[name="settings[check_branch]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  return $form;
}