function ResolverRelationshipConfigure::buildForm

Same name in other branches
  1. 8.x-3.x src/Form/ResolverRelationshipConfigure.php \Drupal\ctools\Form\ResolverRelationshipConfigure::buildForm()

Overrides FormInterface::buildForm

File

src/Form/ResolverRelationshipConfigure.php, line 61

Class

ResolverRelationshipConfigure
Configure Relationships Resolver form.

Namespace

Drupal\ctools\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $context = 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($context)) {
        $id = $context;
        $contexts = $this->getContexts($cached_values);
        $context = $contexts[$id]['context'];
        $label = $contexts[$id]['label'];
        $machine_name = $contexts[$id]['machine_name'];
        $description = $contexts[$id]['description'];
        // Conditionally set this form element so that we can update or add.
        $form['id'] = [
            '#type' => 'value',
            '#value' => $id,
        ];
    }
    else {
        $label = '';
        $machine_name = '';
        $description = '';
    }
    $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $form['context'] = [
        '#type' => 'value',
        '#value' => $context,
    ];
    $form['label'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Label'),
        '#default_value' => $label,
        '#required' => TRUE,
    ];
    $form['machine_name'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Machine Name'),
        '#default_value' => $machine_name,
        '#required' => TRUE,
    ];
    $form['description'] = [
        '#type' => 'textarea',
        '#title' => $this->t('Description'),
        '#default_value' => $description,
    ];
    $form['submit'] = [
        '#type' => 'submit',
        '#value' => $this->t('Save'),
        '#ajax' => [
            'callback' => [
                $this,
                'ajaxSave',
            ],
        ],
    ];
    return $form;
}