GeneralForm.php in Frequently Asked Questions 8
File
src/Form/GeneralForm.php
View source
<?php
namespace Drupal\faq\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class GeneralForm extends ConfigFormBase {
public function getFormId() {
return 'faq_general_settings_form';
}
protected function getEditableConfigNames() {
return [];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$faq_settings = $this
->config('faq.settings');
$form['faq_title'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Title'),
'#default_value' => $faq_settings
->get('title'),
);
$form['body_filter']['faq_description'] = array(
'#type' => 'textarea',
'#title' => $this
->t('FAQ Description'),
'#default_value' => $faq_settings
->get('description'),
'#description' => $this
->t('Your FAQ description. This will be placed at the top of the page, above the questions and can serve as an introductory text.'),
'#rows' => 5,
);
$form['faq_custom_breadcrumbs'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Create custom breadcrumbs for the FAQ'),
'#description' => $this
->t('This option set the breadcrumb path to "%home > %faqtitle > category trail".', array(
'%home' => $this
->t('Home'),
'%faqtitle' => $faq_settings
->get('title'),
)),
'#default_value' => $faq_settings
->get('custom_breadcrumbs'),
);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->cleanValues();
$this
->configFactory()
->getEditable('faq.settings')
->set('title', $form_state
->getValue('faq_title'))
->set('description', $form_state
->getValue('faq_description'))
->set('custom_breadcrumbs', $form_state
->getValue('faq_custom_breadcrumbs'))
->save();
parent::submitForm($form, $form_state);
}
}