Security update for permissions_by_term
[yaffs-website] / web / modules / contrib / permissions_by_term / src / Form / SettingsForm.php
1 <?php
2
3 namespace Drupal\permissions_by_term\Form;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8
9 class SettingsForm extends ConfigFormBase {
10
11   /**
12    * {@inheritdoc}
13    */
14   public function getFormId() {
15     return 'permissions_by_term_settings';
16   }
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function getEditableConfigNames() {
22     return [
23       'permissions_by_term.settings'
24     ];
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function buildForm(array $form, FormStateInterface $form_state) {
31     $config = $this->config('permissions_by_term.settings');
32
33     $form = parent::buildForm($form, $form_state);
34
35     $description = <<<EOT
36 By default users have granted access to an node, as long they have access to a <strong>single</strong>
37 related taxonomy term. If the single term restriction option is checked, they must
38 have access to <strong>all</strong> related taxonomy terms to access an node. Because as soon the
39 specific node is related to a "single" non-permitted taxonomy term, the access will 
40 be disallowed.
41 EOT;
42
43     $form['single_term_restriction'] = [
44       '#type' => 'checkbox',
45       '#title' => t('Single Term Restriction'),
46       '#description' => t($description),
47       '#default_value' => \Drupal::config('permissions_by_term.settings.single_term_restriction')->get('value'),
48     ];
49
50     return parent::buildForm($form, $form_state);
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function submitForm(array &$form, FormStateInterface $form_state) {
57     \Drupal::configFactory()
58       ->getEditable('permissions_by_term.settings.single_term_restriction')
59       ->set('value', $form_state->getValue('single_term_restriction'))
60       ->save();
61
62     node_access_rebuild(true);
63
64     parent::submitForm($form, $form_state);
65   }
66
67 }