You are here

public function SerialLauncher::buildConfigurationForm in Ultimate Cron 8.2

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides CronPlugin::buildConfigurationForm

File

src/Plugin/ultimate_cron/Launcher/SerialLauncher.php, line 52

Class

SerialLauncher
Ultimate Cron launcher plugin class.

Namespace

Drupal\ultimate_cron\Plugin\ultimate_cron\Launcher

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['timeouts'] = array(
    '#type' => 'fieldset',
    '#title' => t('Timeouts'),
  );
  $form['launcher'] = array(
    '#type' => 'fieldset',
    '#title' => t('Launching options'),
  );
  $form['timeouts']['lock_timeout'] = array(
    '#title' => t("Job lock timeout"),
    '#type' => 'textfield',
    '#default_value' => $this->configuration['timeouts']['lock_timeout'],
    '#description' => t('Number of seconds to keep lock on job.'),
    '#fallback' => TRUE,
    '#required' => TRUE,
  );

  // @todo: Figure this out when converting global settings to use plugin
  // classes.
  if (FALSE) {
    $form['timeouts']['max_execution_time'] = array(
      '#title' => t("Maximum execution time"),
      '#type' => 'textfield',
      '#default_value' => $this->configuration['timeouts']['max_execution_time'],
      '#description' => t('Maximum execution time for a cron run in seconds.'),
      '#fallback' => TRUE,
      '#required' => TRUE,
    );
    $form['launcher']['max_threads'] = array(
      '#title' => t("Maximum number of launcher threads"),
      '#type' => 'number',
      '#default_value' => $this->configuration['launcher']['max_threads'],
      '#description' => t('The maximum number of launch threads that can be running at any given time.'),
      '#fallback' => TRUE,
      '#required' => TRUE,
      '#weight' => 1,
    );
    return $form;
  }
  else {
    $max_threads = isset($this->configuration['launcher']['max_threads']) ? $this->configuration['launcher']['max_threads'] : 1;
  }
  $options = array(
    'any' => t('-- Any -- '),
    'fixed' => t('-- Fixed -- '),
  );
  for ($i = 1; $i <= $max_threads; $i++) {
    $options[$i] = $i;
  }
  $form['launcher']['thread'] = array(
    '#title' => t("Run in thread"),
    '#type' => 'select',
    '#default_value' => isset($this->configuration['launcher']['thread']) ? $this->configuration['launcher']['thread'] : 'any',
    '#options' => $options,
    '#description' => t('Which thread to run in when invoking with ?thread=N. Note: This setting only has an effect when cron is run through cron.php with an argument ?thread=N or through Drush with --options=thread=N.'),
    '#fallback' => TRUE,
    '#required' => TRUE,
    '#weight' => 2,
  );
  return $form;
}