You are here

public function ConditionConfigure::buildForm in Chaos Tool Suite (ctools) 8.3

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 FormInterface::buildForm

File

src/Form/ConditionConfigure.php, line 66

Class

ConditionConfigure
Base class for condition configur operations.

Namespace

Drupal\ctools\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $condition = NULL, $tempstore_id = NULL, $machine_name = NULL) {
  $this->tempstore_id = $tempstore_id;
  $this->machine_name = $machine_name;
  $cached_values = $this->tempstore
    ->get($this->tempstore_id)
    ->get($this->machine_name);
  if (is_numeric($condition) || Uuid::isValid($condition)) {
    $id = $condition;
    $condition = $this
      ->getConditions($cached_values)[$id];
    $instance = $this->manager
      ->createInstance($condition['id'], $condition);
  }
  else {
    $instance = $this->manager
      ->createInstance($condition, []);
  }
  $form_state
    ->setTemporaryValue('gathered_contexts', $this
    ->getContexts($cached_values));

  /** @var $instance \Drupal\Core\Condition\ConditionInterface */
  $form = $instance
    ->buildConfigurationForm($form, $form_state);
  if (isset($id)) {

    // Conditionally set this form element so that we can update or add.
    $form['id'] = [
      '#type' => 'value',
      '#value' => $id,
    ];
  }
  $form['instance'] = [
    '#type' => 'value',
    '#value' => $instance,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#ajax' => [
      'callback' => [
        $this,
        'ajaxSave',
      ],
    ],
  ];
  return $form;
}