function ManageResolverRelationships::buildForm

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

Overrides FormInterface::buildForm

File

src/Form/ManageResolverRelationships.php, line 81

Class

ManageResolverRelationships
Provider manage resolver relationships.

Namespace

Drupal\ctools\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $cached_values = $form_state->getTemporaryValue('wizard');
    $this->machine_name = $cached_values['id'];
    $form['items'] = [
        '#type' => 'markup',
        '#prefix' => '<div id="configured-relationships">',
        '#suffix' => '</div>',
        '#theme' => 'table',
        '#header' => [
            $this->t('Context ID'),
            $this->t('Label'),
            $this->t('Data Type'),
            $this->t('Options'),
        ],
        '#rows' => $this->renderRows($cached_values),
        '#empty' => $this->t('No relationships have been added.'),
    ];
    $form['relationships'] = [
        '#type' => 'select',
        '#title' => $this->t('Add a relationship'),
        '#options' => $this->getAvailableRelationships($cached_values),
    ];
    $form['add_relationship'] = [
        '#type' => 'submit',
        '#name' => 'add',
        '#value' => $this->t('Add Relationship'),
        '#ajax' => [
            'callback' => [
                $this,
                'addRelationship',
            ],
            'event' => 'click',
        ],
        '#submit' => [
            'callback' => [
                $this,
                'submitForm',
            ],
        ],
    ];
    return $form;
}