You are here

public function LibraryListForm::buildForm in Skinr 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 ConfirmFormBase::buildForm

File

skinr_ui/src/Form/LibraryListForm.php, line 58
Contains \Drupal\skinr_ui\Form\LibraryListForm.

Class

LibraryListForm
Provides skinr plugin installation interface.

Namespace

Drupal\skinr_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $theme = NULL) {
  $form['edited_theme'] = array(
    '#type' => 'value',
    '#value' => $theme,
  );
  $skin_infos = skinr_get_skin_info();
  if (empty($skin_infos)) {
    $form['skins_empty'] = array(
      '#markup' => t("You don't have any skins to manage."),
    );
    return $form;
  }

  // Confirmation form.
  $storage =& $form_state
    ->getStorage();
  if (!empty($storage['sids'])) {
    $form['sids'] = array(
      '#theme' => 'item_list',
      '#items' => array_map(function ($skin) {
        return $skin['title'];
      }, array_intersect_key($skin_infos, array_flip($storage['skin_infos']))),
    );

    // @todo Test this works properly.
    return parent::buildForm($form, $form_state);
  }

  // Apply overridden status.
  foreach ($skin_infos as $name => $skin_info) {
    $skin_infos[$name]['status'] = skinr_skin_info_status_get($skin_info);
  }
  $groups = skinr_get_group_info();
  uasort($skin_infos, array(
    '\\Drupal\\Component\\Utility\\SortArray',
    'sortByTitleElement',
  ));
  $form['skin_infos'] = array(
    '#tree' => TRUE,
  );

  // Iterate through each of the skin_infos.
  foreach ($skin_infos as $name => $skin_info) {
    $group = (string) $groups[$skin_info['group']]['title'];
    $form['skin_infos'][$group][$name] = $this
      ->buildRow($skin_info, $theme);
  }

  // Add basic information to the fieldsets.
  foreach (Element::children($form['skin_infos']) as $package) {
    $form['skin_infos'][$package] += array(
      '#type' => 'details',
      '#title' => $this
        ->t($package),
      '#open' => TRUE,
      '#theme' => 'skinr_ui_library_details',
      '#attributes' => array(
        'class' => array(
          'package-listing',
        ),
      ),
    );
  }
  $form['#attached']['library'][] = 'skinr_ui/admin.styling';
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['actions']['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to defaults'),
  );
  return $form;
}