Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Ajax / AjaxHelperTrait.php
1 <?php
2
3 namespace Drupal\Core\Ajax;
4
5 use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
6
7 /**
8  * Provides a helper to determine if the current request is via AJAX.
9  *
10  * @internal
11  */
12 trait AjaxHelperTrait {
13
14   /**
15    * Determines if the current request is via AJAX.
16    *
17    * @return bool
18    *   TRUE if the current request is via AJAX, FALSE otherwise.
19    */
20   protected function isAjax() {
21     foreach (['drupal_ajax', 'drupal_modal', 'drupal_dialog'] as $wrapper) {
22       if (strpos($this->getRequestWrapperFormat(), $wrapper) !== FALSE) {
23         return TRUE;
24       }
25     }
26     return FALSE;
27   }
28
29   /**
30    * Gets the wrapper format of the current request.
31    *
32    * @string
33    *   The wrapper format.
34    */
35   protected function getRequestWrapperFormat() {
36     return \Drupal::request()->get(MainContentViewSubscriber::WRAPPER_FORMAT);
37   }
38
39 }