You are here

public function SettingsForm::buildForm in Opigno dashboard 8

Same name and namespace in other branches
  1. 3.x src/Form/SettingsForm.php \Drupal\opigno_dashboard\Form\SettingsForm::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/SettingsForm.php, line 75

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\opigno_dashboard\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#title'] = $this
    ->t('Dashboard settings');
  $config = $this
    ->config('opigno_dashboard.settings');
  $config_blocks = $config
    ->get('blocks');
  $config_theme = $config
    ->get('theme');
  $blocks = $this->blockService
    ->getAllBlocks();
  $themes = [];
  foreach ($this->themeHandler
    ->listInfo() as $theme) {
    $themes[$theme
      ->getName()] = $theme->info['name'];
  }
  $form['theme'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Theme selection'),
    '#options' => $themes,
    '#default_value' => isset($config_theme) ? $config_theme : $this
      ->config('system.theme')
      ->get('default'),
    '#description' => $this
      ->t("The dashboard blocks will be created under this theme. A region named 'content' is required."),
  ];
  $form['blocks_label'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Dashboard Blocks'),
  ];
  $form['blocks'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Name'),
      $this
        ->t('Available'),
      $this
        ->t('Mandatory'),
    ],
  ];
  foreach ($blocks as $id => $block) {
    $form['blocks'][$id]['name'] = [
      '#markup' => $block['admin_label'],
    ];
    $form['blocks'][$id]['available'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Available'),
      '#title_display' => 'invisible',
      '#default_value' => isset($config_blocks[$id]['available']) ? $config_blocks[$id]['available'] : NULL,
    ];
    $form['blocks'][$id]['mandatory'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Mandatory'),
      '#title_display' => 'invisible',
      '#default_value' => isset($config_blocks[$id]['mandatory']) ? $config_blocks[$id]['mandatory'] : NULL,
    ];
  }
  return parent::buildForm($form, $form_state);
}