Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AjaxHelperTrait.php

trait AjaxHelperTrait

Provides a helper to determine if the current request is via AJAX.

@internal

Hierarchy

  • trait \Drupal\Core\Ajax\AjaxHelperTrait
5 files declare their use of AjaxHelperTrait
AddSectionController.php in core/modules/layout_builder/src/Controller/AddSectionController.php
ChooseBlockController.php in core/modules/layout_builder/src/Controller/ChooseBlockController.php
ChooseSectionController.php in core/modules/layout_builder/src/Controller/ChooseSectionController.php
LayoutBuilder.php in core/modules/layout_builder/src/Element/LayoutBuilder.php
WorkspaceListBuilder.php in core/modules/workspaces/src/WorkspaceListBuilder.php

File

core/lib/Drupal/Core/Ajax/AjaxHelperTrait.php, line 12

Namespace

Drupal\Core\Ajax
View source
trait AjaxHelperTrait {
    
    /**
     * Determines if the current request is via AJAX.
     *
     * @return bool
     *   TRUE if the current request is via AJAX, FALSE otherwise.
     */
    protected function isAjax() {
        $wrapper_format = $this->getRequestWrapperFormat() ?? '';
        return str_contains($wrapper_format, 'drupal_ajax') || str_contains($wrapper_format, 'drupal_modal') || str_contains($wrapper_format, 'drupal_dialog');
    }
    
    /**
     * Gets the wrapper format of the current request.
     *
     * @return string|null
     *   The wrapper format. NULL if the wrapper format is not set.
     */
    protected function getRequestWrapperFormat() {
        return \Drupal::request()->get(MainContentViewSubscriber::WRAPPER_FORMAT);
    }

}

Members

Title Sort descending Modifiers Object type Summary
AjaxHelperTrait::getRequestWrapperFormat protected function Gets the wrapper format of the current request.
AjaxHelperTrait::isAjax protected function Determines if the current request is via AJAX.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal