You are here

public function DomainMenuAccessSettingsForm::buildForm in Domain Menu Access 8

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/DomainMenuAccessSettingsForm.php, line 28

Class

DomainMenuAccessSettingsForm

Namespace

Drupal\domain_menu_access\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('domain_menu_access.settings')
    ->get('menu_enabled');
  if (!$config) {
    $config = [];
  }
  $menu = Menu::loadMultiple();
  if (empty($menu)) {
    $form['markup'] = [
      '#markup' => $this
        ->t('Your menu list is empty. Please, try add the menu and return here.'),
    ];
  }
  else {
    $form['description'] = [
      '#markup' => $this
        ->t('Please, select menu for enable control by domain records.'),
    ];

    /** @var \Drupal\system\Entity\Menu $item */
    foreach ($menu as $key => $item) {
      $form[$key] = [
        '#type' => 'checkbox',
        '#title' => $item
          ->label(),
        '#default_value' => in_array($key, $config) ? '1' : '',
        '#description' => $item
          ->getDescription(),
      ];
    }
  }
  return parent::buildForm($form, $form_state);
}