00b37c3ec88cd36b7c182b4d42046cb810f18cef
[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     $form = parent::buildForm($form, $form_state);
32     $description = <<<EOT
33 By default users are granted access content, as long they have access to a <strong>single</strong>
34 related taxonomy term. If the single term restriction option is checked, they must
35 have access to <strong>all</strong> related taxonomy terms to access an node.
36 EOT;
37
38     $form['single_term_restriction'] = [
39       '#type' => 'checkbox',
40       '#title' => t('Single Term Restriction'),
41       '#description' => t($description),
42       '#default_value' => \Drupal::config('permissions_by_term.settings.single_term_restriction')->get('value'),
43     ];
44
45     return parent::buildForm($form, $form_state);
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function submitForm(array &$form, FormStateInterface $form_state) {
52     \Drupal::configFactory()
53       ->getEditable('permissions_by_term.settings.single_term_restriction')
54       ->set('value', $form_state->getValue('single_term_restriction'))
55       ->save();
56
57     node_access_rebuild(true);
58
59     parent::submitForm($form, $form_state);
60   }
61
62 }