DomainAccessSettingsForm.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Drupal\domain_access\Form;
  3. use Drupal\Core\Form\ConfigFormBase;
  4. use Drupal\Core\Form\FormStateInterface;
  5. /**
  6. * Class DomainAccessSettingsForm.
  7. *
  8. * @package Drupal\domain_access\Form
  9. */
  10. class DomainAccessSettingsForm extends ConfigFormBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function getFormId() {
  15. return 'domain_access_settings';
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function getEditableConfigNames() {
  21. return ['domain_access.settings'];
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function buildForm(array $form, FormStateInterface $form_state) {
  27. $config = $this->config('domain_access.settings');
  28. $form['node_advanced_tab'] = [
  29. '#type' => 'checkbox',
  30. '#title' => $this->t('Move Domain Access fields to advanced node settings.'),
  31. '#default_value' => $config->get('node_advanced_tab'),
  32. '#description' => $this->t('When checked the Domain Access fields will be shown as a tab in the advanced settings on node edit form. However, if you have placed the fields in a field group already, they will not be moved.'),
  33. ];
  34. $form['node_advanced_tab_open'] = [
  35. '#type' => 'checkbox',
  36. '#title' => $this->t('Open the Domain Access details.'),
  37. '#description' => $this->t('Set the details tab to be open by default.'),
  38. '#default_value' => $config->get('node_advanced_tab_open'),
  39. '#states' => [
  40. 'visible' => [
  41. ':input[name="node_advanced_tab"]' => ['checked' => TRUE],
  42. ],
  43. ],
  44. ];
  45. return parent::buildForm($form, $form_state);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function submitForm(array &$form, FormStateInterface $form_state) {
  51. $this->config('domain_access.settings')
  52. ->set('node_advanced_tab', (bool) $form_state->getValue('node_advanced_tab'))
  53. ->set('node_advanced_tab_open', (bool) $form_state->getValue('node_advanced_tab_open'))
  54. ->save();
  55. parent::submitForm($form, $form_state);
  56. }
  57. }