You are here

public function AdminSettings::buildForm in Calendar Systems 8.2

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/AdminSettings.php, line 32
Contains Drupal\CalendarSystems\Form\AdminSettings.

Class

AdminSettings

Namespace

Drupal\calendar_systems\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('calendar_systems.settings');
  Helpers::calendar_systems_add_strings();
  if (Helpers::calendar_systems_is_patch_applied() !== TRUE) {
    $this
      ->messenger()
      ->addWarning($this
      ->t('There is a problem with calendar systems installation, please visit <a href=":readme-link">site status page</a> for more information.', [
      ':readme-link' => $this
        ->getUrlGenerator()
        ->generateFromRoute('system.status'),
    ]));
  }

  // build the overview form array.
  $form['profiles'] = array();
  $form['profiles']['#type'] = 'table';

  //$form['profiles']['#caption'] = $this->t('Sample Table');
  $form['profiles']['#header'] = [
    $this
      ->t('Language'),
    $this
      ->t('Calendar system'),
    $this
      ->t('Operations'),
  ];

  // Set initials.
  $profiles = Helpers::calendar_systems_profiles();

  //print_r($profiles);
  $languages = Helpers::calendar_systems_langauges();

  //$calendar_systems = Helpers::_calendar_systems_plugins();
  $options = Helpers::calendar_systems_profiles_simple();

  // Table rows:
  foreach ($languages as $id => $language) {

    // Language:
    $form['profiles'][$id]['language'] = array(
      '#type' => 'markup',
      '#plain_text' => $language['name'],
    );

    // Calendar systems:
    $form['profiles'][$id]['calendar_system'] = array(
      '#type' => 'select',
      '#options' => $options,
      '#id' => "edit-editor-{$id}",
      '#default_value' => isset($profiles[$id]) ? $profiles[$id]['calendar_system'] : '',
      '#disabled' => isset($profiles[$id]) ? (bool) $profiles[$id]['calendar_system'] : FALSE,
    );

    // Operation links:
    if (isset($profiles[$id]) && !empty($profiles[$id]['calendar_system'])) {
      $form['profiles'][$id]['remove'] = array(
        '#type' => 'markup',
        '#markup' => $this
          ->getLinkGenerator()
          ->generate($this
          ->t('Remove'), new Url("calendar_systems.admin.profiles.delete", [
          'id' => $id,
        ])),
      );
    }
  }
  $form['form_fields_date_picker'] = array(
    '#type' => 'fieldset',
    '#title' => t('Javascript Date Picker'),
  );
  if (\Drupal::moduleHandler()
    ->moduleExists('jquery_calendar')) {
    $form['form_fields_date_picker']['core_text_date_fields'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add to text date fields'),
      '#default_value' => $config
        ->get('js_date_picker_core_text_date_fields'),
    );
  }
  else {
    $form['form_fields_date_picker']['note'] = array(
      '#type' => 'markup',
      '#markup' => t('You must enable %s module in order to be able to use this feature', array(
        '%s' => 'jquery calendars',
      )),
    );
  }
  return parent::buildForm($form, $form_state);
}