diff --git a/web/profiles/custom/os2loop/src/Form/SettingsForm.php b/web/profiles/custom/os2loop/src/Form/SettingsForm.php index 5033883bb..42f247bec 100644 --- a/web/profiles/custom/os2loop/src/Form/SettingsForm.php +++ b/web/profiles/custom/os2loop/src/Form/SettingsForm.php @@ -95,6 +95,23 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $config->get('taxonomy_vocabulary'), ]; + $form['os2loop_question'] = [ + '#tree' => TRUE, + '#type' => 'fieldset', + '#title' => $this->t('Question settings'), + '#states' => [ + 'visible' => [ + [':input[name="node_type[os2loop_question]"]' => ['checked' => TRUE]], + ], + ], + + 'enable_rich_text' => [ + '#type' => 'checkbox', + '#title' => $this->t('Enable rich text in questions'), + '#default_value' => $config->get('os2loop_question.enable_rich_text'), + ], + ]; + $form['search_settings'] = [ '#tree' => TRUE, '#type' => 'fieldset', @@ -132,6 +149,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $this->configFactory->getEditable(static::SETTINGS) ->set('node_type', $form_state->getValue('node_type')) ->set('taxonomy_vocabulary', $form_state->getValue('taxonomy_vocabulary')) + ->set('os2loop_question', $form_state->getValue('os2loop_question')) ->set('search_settings', $form_state->getValue('search_settings')) ->save(); diff --git a/web/profiles/custom/os2loop/src/Helper/Helper.php b/web/profiles/custom/os2loop/src/Helper/Helper.php index dfd9b3239..8d569a2e8 100644 --- a/web/profiles/custom/os2loop/src/Helper/Helper.php +++ b/web/profiles/custom/os2loop/src/Helper/Helper.php @@ -57,6 +57,7 @@ public function nodeAccess(NodeInterface $node, $op, AccountInterface $account): */ public function formAlter(&$form, FormStateInterface $form_state, $form_id) { $this->hideTaxonomyVocabularies($form); + $this->handleTextFormats($form, $form_state, $form_id); } /** @@ -157,4 +158,20 @@ private function hideTaxonomyVocabularies(array &$element) { } } + /** + * Handle text formats. + */ + private function handleTextFormats(&$form, FormStateInterface $form_state, $form_id) { + switch ($form_id) { + case 'node_os2loop_question_form': + case 'node_os2loop_question_edit_form': + $currentFormat = $form['os2loop_question_content']['widget'][0]['#format'] ?? NULL; + $useRichText = $this->config->get('os2loop_question.enable_rich_text') || 'os2loop_question_rich_text' === $currentFormat; + $form['os2loop_question_content']['widget'][0]['#better_formats']['settings']['allowed_formats'] = + $useRichText ? ['os2loop_question_rich_text' => 'os2loop_question_rich_text'] : ['os2loop_question_plain_text' => 'os2loop_question_plain_text']; + + break; + } + } + }