Yaffs site version 1.1
[yaffs-website] / web / modules / contrib / advagg / src / Form / AdvaggFormBase.php
1 <?php
2
3 namespace Drupal\advagg\Form;
4
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Form\ConfigFormBase;
7 use Drupal\Core\Form\FormBuilderInterface;
8 use Drupal\Core\State\StateInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10 use Symfony\Component\HttpFoundation\RequestStack;
11
12 /**
13  * View AdvAgg information for this site.
14  */
15 abstract class AdvaggFormBase extends ConfigFormBase {
16
17   /**
18    * The AdvAgg file status state information storage service.
19    *
20    * @var \Drupal\Core\State\StateInterface
21    */
22   protected $advaggFiles;
23
24   /**
25    * The AdvAgg aggregates state information storage service.
26    *
27    * @var \Drupal\Core\State\StateInterface
28    */
29   protected $advaggAggregates;
30
31   /**
32    * The request stack.
33    *
34    * @var \Symfony\Component\HttpFoundation\RequestStack
35    */
36   protected $requestStack;
37
38   /**
39    * Constructs a SettingsForm object.
40    *
41    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
42    *   The factory for configuration objects.
43    * @param \Drupal\Core\State\StateInterface $advagg_files
44    *   The AdvAgg file status state information storage service.
45    * @param \Drupal\Core\State\StateInterface $advagg_aggregates
46    *   The AdvAgg aggregate state information storage service.
47    * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
48    *   The request stack.
49    */
50   public function __construct(ConfigFactoryInterface $config_factory, StateInterface $advagg_files, StateInterface $advagg_aggregates, RequestStack $request_stack) {
51     parent::__construct($config_factory);
52     $this->advaggFiles = $advagg_files;
53     $this->advaggAggregates = $advagg_aggregates;
54     $this->requestStack = $request_stack;
55   }
56
57   /**
58    * {@inheritdoc}
59    */
60   public static function create(ContainerInterface $container) {
61     return new static(
62       $container->get('config.factory'),
63       $container->get('state.advagg.files'),
64       $container->get('state.advagg.aggregates'),
65       $container->get('request_stack')
66     );
67   }
68
69   /**
70    * Checks if the form was submitted by AJAX.
71    *
72    * @return bool
73    *   TRUE if the form was submitted via AJAX, otherwise FALSE.
74    */
75   protected function isAjax() {
76     $request = $this->requestStack->getCurrentRequest();
77     if ($request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
78       return TRUE;
79     }
80     return FALSE;
81   }
82
83 }