function ManageConditions::add

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

File

src/Form/ManageConditions.php, line 114

Class

ManageConditions

Namespace

Drupal\ctools\Form

Code

public function add(array &$form, FormStateInterface $form_state) {
    $condition = $form_state->getValue('conditions');
    $content = $this->formBuilder
        ->getForm($this->getConditionClass(), $condition, $this->getTempstoreId(), $this->machine_name);
    $content['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $cached_values = $form_state->getTemporaryValue('wizard');
    [
        ,
        $route_parameters,
    ] = $this->getOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('conditions'));
    $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 Required Context'), $content, [
        'width' => '700',
    ]));
    return $response;
}