Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions web/profiles/custom/os2loop/src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();

Expand Down
17 changes: 17 additions & 0 deletions web/profiles/custom/os2loop/src/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
}

}