Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / blazy / blazy_ui / src / Form / BlazySettingsForm.php
1 <?php
2
3 namespace Drupal\blazy_ui\Form;
4
5 use Drupal\Core\Url;
6 use Drupal\Core\Form\ConfigFormBase;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Defines blazy admin settings form.
11  */
12 class BlazySettingsForm extends ConfigFormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormId() {
18     return 'blazy_settings';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function getEditableConfigNames() {
25     return ['blazy.settings'];
26   }
27
28   /**
29    * Implements \Drupal\Core\Form\FormInterface::buildForm().
30    */
31   public function buildForm(array $form, FormStateInterface $form_state) {
32     $config = $this->config('blazy.settings');
33
34     $form['admin_css'] = [
35       '#type'          => 'checkbox',
36       '#title'         => $this->t('Admin CSS'),
37       '#default_value' => $config->get('admin_css'),
38       '#description'   => $this->t('Uncheck to disable blazy related admin compact form styling, only if not compatible with your admin theme.'),
39     ];
40
41     $form['responsive_image'] = [
42       '#type'          => 'checkbox',
43       '#title'         => $this->t('Support Responsive image'),
44       '#default_value' => $config->get('responsive_image'),
45       '#description'   => $this->t('Check to support lazyloading for the core Responsive image module. Be sure to use Blazy formatter to have relevant styling.'),
46     ];
47
48     $form['one_pixel'] = [
49       '#type'          => 'checkbox',
50       '#title'         => $this->t('One pixel placeholder'),
51       '#default_value' => $config->get('one_pixel'),
52       '#description'   => $this->t('By default a one pixel image is the placeholder for lazyloaded Responsive image. Useful to perform a lot better. Uncheck to disable, and use Drupal-managed smallest/fallback image style instead. Be sure to add proper dimensions or at least min-height/min-width via CSS accordingly to avoid layout reflow since Aspect ratio is not supported with Responsive image yet. Disabling this will result in downloading fallback image as well for non-PICTURE element (double downloads).'),
53     ];
54
55     $form['blazy'] = [
56       '#type'        => 'container',
57       '#tree'        => TRUE,
58       '#title'       => $this->t('Blazy JS settings'),
59       '#description' => $this->t('The following are JS related settings.'),
60     ];
61
62     $form['blazy']['loadInvisible'] = [
63       '#type'          => 'checkbox',
64       '#title'         => $this->t('Load invisible'),
65       '#default_value' => $config->get('blazy.loadInvisible'),
66       '#description'   => $this->t('Set to true if you want to load invisible (hidden) elements.'),
67     ];
68
69     $form['blazy']['offset'] = [
70       '#type'          => 'textfield',
71       '#title'         => $this->t('Offset'),
72       '#default_value' => $config->get('blazy.offset'),
73       '#description'   => $this->t("The offset controls how early you want the elements to be loaded before they're visible. Default is <strong>100</strong>, so 100px before an element is visible it'll start loading."),
74       '#field_suffix'  => 'px',
75       '#maxlength'     => 5,
76       '#size'          => 10,
77     ];
78
79     $form['blazy']['saveViewportOffsetDelay'] = [
80       '#type'          => 'textfield',
81       '#title'         => $this->t('Save viewport offset delay'),
82       '#default_value' => $config->get('blazy.saveViewportOffsetDelay'),
83       '#description'   => $this->t('Delay for how often it should call the saveViewportOffset function on resize. Default is <strong>50</strong>ms.'),
84       '#field_suffix'  => 'ms',
85       '#maxlength'     => 5,
86       '#size'          => 10,
87     ];
88
89     return parent::buildForm($form, $form_state);
90   }
91
92   /**
93    * Implements \Drupal\Core\Form\FormInterface::submitForm().
94    */
95   public function submitForm(array &$form, FormStateInterface $form_state) {
96     $this->configFactory->getEditable('blazy.settings')
97       ->set('admin_css', $form_state->getValue('admin_css'))
98       ->set('responsive_image', $form_state->getValue('responsive_image'))
99       ->set('one_pixel', $form_state->getValue('one_pixel'))
100       ->set('blazy.loadInvisible', $form_state->getValue(['blazy', 'loadInvisible']))
101       ->set('blazy.offset', $form_state->getValue(['blazy', 'offset']))
102       ->set('blazy.saveViewportOffsetDelay', $form_state->getValue(['blazy', 'saveViewportOffsetDelay']))
103       ->save();
104
105     // Invalidate the library discovery cache to update the responsive image.
106     \Drupal::service('library.discovery')->clearCachedDefinitions();
107
108     drupal_set_message($this->t('Be sure to <a href=":clear_cache">clear the cache</a> if trouble to see the updated settings', [':clear_cache' => Url::fromRoute('system.performance_settings')->toString()]));
109
110     parent::submitForm($form, $form_state);
111   }
112
113 }