You are here

public function RelationshipConfigure::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/RelationshipConfigure.php, line 61

Class

RelationshipConfigure

Namespace

Drupal\ctools\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $context_id = 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);

  /** @var \Drupal\Core\Plugin\Context\ContextInterface[] $contexts */
  $contexts = $this
    ->getContexts($cached_values);
  $context_object = $this->resolver
    ->convertTokenToContext($context_id, $contexts);
  $form['id'] = [
    '#type' => 'value',
    '#value' => $context_id,
  ];
  $form['context_object'] = [
    '#type' => 'value',
    '#value' => $context_object,
  ];
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Context label'),
    '#default_value' => !empty($contexts[$context_id]) ? $contexts[$context_id]
      ->getContextDefinition()
      ->getLabel() : $this->resolver
      ->getLabelByToken($context_id, $contexts),
    '#required' => TRUE,
  ];
  $form['context_data'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Data type'),
    '#markup' => $context_object
      ->getContextDefinition()
      ->getDataType(),
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#ajax' => [
      'callback' => [
        $this,
        'ajaxSave',
      ],
    ],
  ];
  return $form;
}