function RelationshipConfigure::buildForm

Same name in other branches
  1. 4.0.x src/Form/RelationshipConfigure.php \Drupal\ctools\Form\RelationshipConfigure::buildForm()

Overrides FormInterface::buildForm

File

src/Form/RelationshipConfigure.php, line 78

Class

RelationshipConfigure
Configure Relationship Form.

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;
}