Loading src/Form/Steps/AddServices.php +37 −6 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\tacjs\Form\Steps; use Drupal\Core\Config\Config; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; Loading Loading @@ -78,10 +79,22 @@ class AddServices extends ConfigFormBase { } /** * {@inheritdoc} * Get configuration. * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function getConfig() { return $this->config('tacjs.settings'); } /** * Add elements to form. * * @param array $form * @param \Drupal\Core\Config\Config $config * * @return void */ protected function addFormElements(array &$form, Config $config) { foreach ($this->languageManager->getLanguages() as $key => $value) { $langcodes[$key] = $value->getName(); Loading Loading @@ -171,6 +184,15 @@ class AddServices extends ConfigFormBase { // Workaround for #3204238: Uncaught TypeError null user // See https://www.drupal.org/project/tacjs/issues/3204238 $form['service']['type_api']['user_googleFonts']['#attributes']['placeholder'] = 'My Font, My Other:300,700'; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->addFormElements($form, $config); return parent::buildForm($form, $form_state); } Loading Loading @@ -200,10 +222,10 @@ class AddServices extends ConfigFormBase { } /** * {@inheritdoc} * Process submitted configuration. */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function processSubmit(FormStateInterface $form_state, Config $config) { $userSettings = []; foreach ($this->content as $services) { Loading Loading @@ -235,6 +257,15 @@ class AddServices extends ConfigFormBase { } } } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->processSubmit($form_state, $config); $config->save(); Loading src/Form/Steps/EditTexts.php +47 −8 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\tacjs\Form\Steps; use Drupal\Core\Config\Config; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; Loading @@ -27,10 +28,22 @@ class EditTexts extends ConfigFormBase { } /** * {@inheritdoc} * Get configuration. * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function getConfig() { return $this->config('tacjs.settings'); } /** * Add elements to form. * * @param array $form * @param \Drupal\Core\Config\Config $config * * @return void */ protected function addFormElements(array &$form, Config $config) { $form['middleBarHead'] = [ '#type' => 'textarea', Loading Loading @@ -395,17 +408,26 @@ class EditTexts extends ConfigFormBase { '#default_value' => $config->get('texts.mandatoryText'), '#placeholder' => $this->t('This site uses cookies necessary for its proper functioning which cannot be deactivated.'), ]; return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->addFormElements($form, $config); return parent::buildForm($form, $form_state); } $elements = [ /** * Get config key to form_state element mappings. * * @return string[] */ protected function getConfigElementMappings(): array { return [ 'middleBarHead' => 'middleBarHead', 'adblock' => 'adblock', 'adblock_call' => 'adblock_call', Loading Loading @@ -459,6 +481,14 @@ class EditTexts extends ConfigFormBase { 'mandatoryTitle' => 'mandatoryTitle', 'mandatoryText' => 'mandatoryText', ]; } /** * Process submitted configuration. */ protected function processSubmit(FormStateInterface $form_state, Config $config) { $elements = $this->getConfigElementMappings(); foreach ($elements as $key => $element) { if ($form_state->getValue($element)) { Loading @@ -468,6 +498,15 @@ class EditTexts extends ConfigFormBase { $config->clear('texts.' . $key); } } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->processSubmit($form_state, $config); $config->save(); Loading src/Form/Steps/ManageDialog.php +39 −8 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\tacjs\Form\Steps; use Drupal\Core\Config\Config; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; Loading @@ -27,10 +28,22 @@ class ManageDialog extends ConfigFormBase { } /** * {@inheritdoc} * Get configuration. * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function getConfig() { return $this->config('tacjs.settings'); } /** * Add elements to form. * * @param array $form * @param \Drupal\Core\Config\Config $config * * @return void */ protected function addFormElements(array &$form, Config $config) { $form['privacyUrl'] = [ '#type' => 'textfield', Loading Loading @@ -251,6 +264,15 @@ class ManageDialog extends ConfigFormBase { '#min' => 1, '#max' => 365, ]; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->addFormElements($form, $config); return parent::buildForm($form, $form_state); } Loading Loading @@ -281,10 +303,9 @@ class ManageDialog extends ConfigFormBase { } /** * {@inheritdoc} * Process submitted configuration. */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function processSubmit(FormStateInterface $form_state, Config $config) { $config ->set('dialog.privacyUrl', $form_state->getValue('privacyUrl')) Loading Loading @@ -314,8 +335,18 @@ class ManageDialog extends ConfigFormBase { ->set('dialog.mandatoryCta', $form_state->getValue('mandatoryCta')) ->set('dialog.closePopup', $form_state->getValue('closePopup')) ->set('dialog.customCloserId', $form_state->getValue('customCloserId')) ->set('expire', $form_state->getValue('expire')) ->save(); ->set('expire', $form_state->getValue('expire')); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->processSubmit($form_state, $config); $config->save(); parent::submitForm($form, $form_state); } Loading Loading
src/Form/Steps/AddServices.php +37 −6 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\tacjs\Form\Steps; use Drupal\Core\Config\Config; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; Loading Loading @@ -78,10 +79,22 @@ class AddServices extends ConfigFormBase { } /** * {@inheritdoc} * Get configuration. * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function getConfig() { return $this->config('tacjs.settings'); } /** * Add elements to form. * * @param array $form * @param \Drupal\Core\Config\Config $config * * @return void */ protected function addFormElements(array &$form, Config $config) { foreach ($this->languageManager->getLanguages() as $key => $value) { $langcodes[$key] = $value->getName(); Loading Loading @@ -171,6 +184,15 @@ class AddServices extends ConfigFormBase { // Workaround for #3204238: Uncaught TypeError null user // See https://www.drupal.org/project/tacjs/issues/3204238 $form['service']['type_api']['user_googleFonts']['#attributes']['placeholder'] = 'My Font, My Other:300,700'; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->addFormElements($form, $config); return parent::buildForm($form, $form_state); } Loading Loading @@ -200,10 +222,10 @@ class AddServices extends ConfigFormBase { } /** * {@inheritdoc} * Process submitted configuration. */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function processSubmit(FormStateInterface $form_state, Config $config) { $userSettings = []; foreach ($this->content as $services) { Loading Loading @@ -235,6 +257,15 @@ class AddServices extends ConfigFormBase { } } } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->processSubmit($form_state, $config); $config->save(); Loading
src/Form/Steps/EditTexts.php +47 −8 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\tacjs\Form\Steps; use Drupal\Core\Config\Config; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; Loading @@ -27,10 +28,22 @@ class EditTexts extends ConfigFormBase { } /** * {@inheritdoc} * Get configuration. * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function getConfig() { return $this->config('tacjs.settings'); } /** * Add elements to form. * * @param array $form * @param \Drupal\Core\Config\Config $config * * @return void */ protected function addFormElements(array &$form, Config $config) { $form['middleBarHead'] = [ '#type' => 'textarea', Loading Loading @@ -395,17 +408,26 @@ class EditTexts extends ConfigFormBase { '#default_value' => $config->get('texts.mandatoryText'), '#placeholder' => $this->t('This site uses cookies necessary for its proper functioning which cannot be deactivated.'), ]; return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->addFormElements($form, $config); return parent::buildForm($form, $form_state); } $elements = [ /** * Get config key to form_state element mappings. * * @return string[] */ protected function getConfigElementMappings(): array { return [ 'middleBarHead' => 'middleBarHead', 'adblock' => 'adblock', 'adblock_call' => 'adblock_call', Loading Loading @@ -459,6 +481,14 @@ class EditTexts extends ConfigFormBase { 'mandatoryTitle' => 'mandatoryTitle', 'mandatoryText' => 'mandatoryText', ]; } /** * Process submitted configuration. */ protected function processSubmit(FormStateInterface $form_state, Config $config) { $elements = $this->getConfigElementMappings(); foreach ($elements as $key => $element) { if ($form_state->getValue($element)) { Loading @@ -468,6 +498,15 @@ class EditTexts extends ConfigFormBase { $config->clear('texts.' . $key); } } } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->processSubmit($form_state, $config); $config->save(); Loading
src/Form/Steps/ManageDialog.php +39 −8 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\tacjs\Form\Steps; use Drupal\Core\Config\Config; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; Loading @@ -27,10 +28,22 @@ class ManageDialog extends ConfigFormBase { } /** * {@inheritdoc} * Get configuration. * @return \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function getConfig() { return $this->config('tacjs.settings'); } /** * Add elements to form. * * @param array $form * @param \Drupal\Core\Config\Config $config * * @return void */ protected function addFormElements(array &$form, Config $config) { $form['privacyUrl'] = [ '#type' => 'textfield', Loading Loading @@ -251,6 +264,15 @@ class ManageDialog extends ConfigFormBase { '#min' => 1, '#max' => 365, ]; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->addFormElements($form, $config); return parent::buildForm($form, $form_state); } Loading Loading @@ -281,10 +303,9 @@ class ManageDialog extends ConfigFormBase { } /** * {@inheritdoc} * Process submitted configuration. */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('tacjs.settings'); protected function processSubmit(FormStateInterface $form_state, Config $config) { $config ->set('dialog.privacyUrl', $form_state->getValue('privacyUrl')) Loading Loading @@ -314,8 +335,18 @@ class ManageDialog extends ConfigFormBase { ->set('dialog.mandatoryCta', $form_state->getValue('mandatoryCta')) ->set('dialog.closePopup', $form_state->getValue('closePopup')) ->set('dialog.customCloserId', $form_state->getValue('customCloserId')) ->set('expire', $form_state->getValue('expire')) ->save(); ->set('expire', $form_state->getValue('expire')); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->getConfig(); $this->processSubmit($form_state, $config); $config->save(); parent::submitForm($form, $form_state); } Loading