public function SiteBannerConfigurationForm::buildForm in Site Banner 8
Same name and namespace in other branches
- 2.0.x src/Form/SiteBannerConfigurationForm.php \Drupal\site_banner\Form\SiteBannerConfigurationForm::buildForm()
- 1.0.x src/Form/SiteBannerConfigurationForm.php \Drupal\site_banner\Form\SiteBannerConfigurationForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ SiteBannerConfigurationForm.php, line 37
Class
- SiteBannerConfigurationForm
- Class SiteBannerConfigurationForm.
Namespace
Drupal\site_banner\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('site_banner.settings');
$startDate = NULL;
$endDate = NULL;
if ($config
->get('site_banner_start_date')) {
$startDate = new DrupalDateTime($config
->get('site_banner_start_date'));
}
if ($config
->get('site_banner_end_date')) {
$endDate = new DrupalDateTime($config
->get('site_banner_end_date'));
}
$form['status'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Status'),
'#description' => $this
->t('Enable/disable banner. (If set this value to disabled then the date fields will be cleared)'),
'#default_value' => $config
->get('status'),
];
$form['show_header'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Header banner'),
'#description' => $this
->t('Enable/disable banner in the header region'),
'#default_value' => $config
->get('show_header'),
];
$form['show_footer'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Footer banner'),
'#description' => $this
->t('Enable/disable banner in the footer region'),
'#default_value' => $config
->get('show_footer'),
];
$form['site_banner_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Site banner text'),
'#description' => $this
->t('This Text will be display on the top of the page'),
'#default_value' => $config
->get('site_banner_text'),
];
$form['site_banner_color'] = [
'#type' => 'textfield',
'#title' => $this
->t('Site banner hex color'),
'#description' => $this
->t('This color will be used as background color (e.g #FFFFFF)'),
'#default_value' => $config
->get('site_banner_color'),
];
$form['site_banner_start_date'] = [
'#type' => 'datetime',
'#title' => $this
->t('Show banner at specific date'),
'#description' => $this
->t('Show banner at a specific date'),
'#default_value' => $startDate,
];
$form['site_banner_end_date'] = [
'#type' => 'datetime',
'#title' => $this
->t('Hide banner at specific date'),
'#description' => $this
->t('Hide banner at specific date (leave empty if you want to display it permanent)'),
'#default_value' => $endDate,
];
return parent::buildForm($form, $form_state);
}