Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/Ajax/AjaxHelperTrait.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
rev | line source |
---|---|
Chris@17 | 1 <?php |
Chris@17 | 2 |
Chris@17 | 3 namespace Drupal\Core\Ajax; |
Chris@17 | 4 |
Chris@17 | 5 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; |
Chris@17 | 6 |
Chris@17 | 7 /** |
Chris@17 | 8 * Provides a helper to determine if the current request is via AJAX. |
Chris@17 | 9 * |
Chris@17 | 10 * @internal |
Chris@17 | 11 */ |
Chris@17 | 12 trait AjaxHelperTrait { |
Chris@17 | 13 |
Chris@17 | 14 /** |
Chris@17 | 15 * Determines if the current request is via AJAX. |
Chris@17 | 16 * |
Chris@17 | 17 * @return bool |
Chris@17 | 18 * TRUE if the current request is via AJAX, FALSE otherwise. |
Chris@17 | 19 */ |
Chris@17 | 20 protected function isAjax() { |
Chris@17 | 21 foreach (['drupal_ajax', 'drupal_modal', 'drupal_dialog'] as $wrapper) { |
Chris@17 | 22 if (strpos($this->getRequestWrapperFormat(), $wrapper) !== FALSE) { |
Chris@17 | 23 return TRUE; |
Chris@17 | 24 } |
Chris@17 | 25 } |
Chris@17 | 26 return FALSE; |
Chris@17 | 27 } |
Chris@17 | 28 |
Chris@17 | 29 /** |
Chris@17 | 30 * Gets the wrapper format of the current request. |
Chris@17 | 31 * |
Chris@17 | 32 * @string |
Chris@17 | 33 * The wrapper format. |
Chris@17 | 34 */ |
Chris@17 | 35 protected function getRequestWrapperFormat() { |
Chris@17 | 36 return \Drupal::request()->get(MainContentViewSubscriber::WRAPPER_FORMAT); |
Chris@17 | 37 } |
Chris@17 | 38 |
Chris@17 | 39 } |