Security update for permissions_by_term
[yaffs-website] / web / modules / contrib / permissions_by_term / src / Form / SettingsForm.php
diff --git a/web/modules/contrib/permissions_by_term/src/Form/SettingsForm.php b/web/modules/contrib/permissions_by_term/src/Form/SettingsForm.php
new file mode 100644 (file)
index 0000000..fe2dff6
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+namespace Drupal\permissions_by_term\Form;
+
+use Drupal\Core\Form\ConfigFormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+
+class SettingsForm extends ConfigFormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'permissions_by_term_settings';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEditableConfigNames() {
+    return [
+      'permissions_by_term.settings'
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $config = $this->config('permissions_by_term.settings');
+
+    $form = parent::buildForm($form, $form_state);
+
+    $description = <<<EOT
+By default users have granted access to an node, as long they have access to a <strong>single</strong>
+related taxonomy term. If the single term restriction option is checked, they must
+have access to <strong>all</strong> related taxonomy terms to access an node. Because as soon the
+specific node is related to a "single" non-permitted taxonomy term, the access will 
+be disallowed.
+EOT;
+
+    $form['single_term_restriction'] = [
+      '#type' => 'checkbox',
+      '#title' => t('Single Term Restriction'),
+      '#description' => t($description),
+      '#default_value' => \Drupal::config('permissions_by_term.settings.single_term_restriction')->get('value'),
+    ];
+
+    return parent::buildForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    \Drupal::configFactory()
+      ->getEditable('permissions_by_term.settings.single_term_restriction')
+      ->set('value', $form_state->getValue('single_term_restriction'))
+      ->save();
+
+    node_access_rebuild(true);
+
+    parent::submitForm($form, $form_state);
+  }
+
+}