OpenModalDialogCommand example

// Override width option.     switch ($this->mode) {
      case 'wide':
        $options['width'] = 700;
        break;

      case 'extra_wide':
        $options['width'] = 1000;
        break;
    }

    $response->addCommand(new OpenModalDialogCommand($title$content$options));
    return $response;
  }

}
    // the attachments for this Ajax response.     $main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $response->setAttachments($main_content['#attached']);

    // If the main content doesn't provide a title, use the title resolver.     $title = $main_content['#title'] ?? $this->titleResolver->getTitle($request$route_match->getRouteObject());

    // Determine the title: use the title provided by the main content if any,     // otherwise get it from the routing information.     $options = $request->request->all('dialogOptions');

    $response->addCommand(new OpenModalDialogCommand($title$content$options));
    return $response;
  }

}

  protected function dialog($is_modal = FALSE) {
    $content = AjaxTestController::dialogContents();
    $response = new AjaxResponse();
    $title = $this->t('AJAX Dialog & contents');

    // Attach the library necessary for using the Open(Modal)DialogCommand and     // set the attachments for this Ajax response.     $content['#attached']['library'][] = 'core/drupal.dialog.ajax';

    if ($is_modal) {
      $response->addCommand(new OpenModalDialogCommand($title$content));
    }
    else {
      $selector = '#ajax-test-dialog-wrapper-1';
      $response->addCommand(new OpenDialogCommand($selector$title$content));
    }
    return $response;
  }

}
$status_messages = ['#type' => 'status_messages'];
      if ($messages = $renderer->renderRoot($status_messages)) {
        $display = '<div class="views-messages">' . $messages . '</div>';
      }
      $display .= $output;

      $options = [
        'dialogClass' => 'views-ui-dialog js-views-ui-dialog',
        'width' => '75%',
      ];

      $response->addCommand(new OpenModalDialogCommand($title$display$options));

      // Views provides its own custom handling of AJAX form submissions.       // Usually this happens at the same path, but custom paths may be       // specified in $form_state.       $form_url = $form_state->has('url') ? $form_state->get('url')->toString() : Url::fromRoute('<current>')->toString();
      $response->addCommand(new SetFormCommand($form_url));

      if ($section = $form_state->get('#section')) {
        $response->addCommand(new HighlightCommand('.' . Html::cleanCssIdentifier($section)));
      }

      

  public static function openMediaLibrary(array $form, FormStateInterface $form_state) {
    $triggering_element = $form_state->getTriggeringElement();
    $library_ui = \Drupal::service('media_library.ui_builder')->buildUi($triggering_element['#media_library_state']);
    $dialog_options = MediaLibraryUiBuilder::dialogOptions();
    return (new AjaxResponse())
      ->addCommand(new OpenModalDialogCommand($dialog_options['title']$library_ui$dialog_options));
  }

  /** * Validates that newly selected items can be added to the widget. * * Making an invalid selection from the view should not be possible, but we * still validate in case other selection methods (ex: upload) are valid. * * @param array $form * The form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */
Home | Imprint | This part of the site doesn't use cookies.