function ManageResolverRelationships::addRelationship

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

Add relationship.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: Stores information about the state of a form.

File

src/Form/ManageResolverRelationships.php, line 135

Class

ManageResolverRelationships
Provider manage resolver relationships.

Namespace

Drupal\ctools\Form

Code

public function addRelationship(array &$form, FormStateInterface $form_state) {
    $relationship = $form_state->getValue('relationships');
    $content = $this->formBuilder
        ->getForm($this->getContextClass(), $relationship, $this->getTempstoreId(), $this->machine_name);
    $content['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $cached_values = $form_state->getTemporaryValue('wizard');
    [
        ,
        $route_parameters,
    ] = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $relationship);
    $route_name = $this->getAddRoute($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;
}