function ManageContext::addRelationship

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

Add relationship form.

Parameters

array $form: The Drupal Form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Return value

\Drupal\Core\Ajax\AjaxResponse Form ajax repsonse.

File

src/Form/ManageContext.php, line 218

Class

ManageContext
Manage Context Form.

Namespace

Drupal\ctools\Form

Code

public function addRelationship(array &$form, FormStateInterface $form_state) {
    $relationship = $form_state->getValue('relationships');
    $cached_values = $form_state->getTemporaryValue('wizard');
    $content = $this->formBuilder
        ->getForm($this->getRelationshipClass($cached_values), $relationship, $this->getTempstoreId(), $this->machine_name);
    $content['#attached']['library'][] = 'core/drupal.dialog.ajax';
    [
        ,
        $route_parameters,
    ] = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $relationship);
    $route_name = $this->getRelationshipAddRoute($cached_values);
    $route_options = [
        'query' => [
            FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
        ],
    ];
    $url = Url::fromRoute($route_name, $route_parameters, $route_options);
    $content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $url->toString();
    $response = new AjaxResponse();
    $response->addCommand(new OpenModalDialogCommand($this->t('Configure Relationship'), $content, [
        'width' => '700',
    ]));
    return $response;
}