function ThemeExperimentalConfirmForm::buildForm

Same name in other branches
  1. 8.9.x core/modules/system/src/Form/ThemeExperimentalConfirmForm.php \Drupal\system\Form\ThemeExperimentalConfirmForm::buildForm()
  2. 10 core/modules/system/src/Form/ThemeExperimentalConfirmForm.php \Drupal\system\Form\ThemeExperimentalConfirmForm::buildForm()
  3. 11.x core/modules/system/src/Form/ThemeExperimentalConfirmForm.php \Drupal\system\Form\ThemeExperimentalConfirmForm::buildForm()

Overrides ConfirmFormBase::buildForm

File

core/modules/system/src/Form/ThemeExperimentalConfirmForm.php, line 96

Class

ThemeExperimentalConfirmForm
Builds a confirmation form for enabling experimental themes.

Namespace

Drupal\system\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $theme = $form_state->getBuildInfo()['args'][0] ? $form_state->getBuildInfo()['args'][0] : NULL;
    $all_themes = $this->themeList
        ->getList();
    if (!isset($all_themes[$theme])) {
        return $this->redirect('system.themes_page');
    }
    $this->messenger()
        ->addWarning($this->t('Experimental themes are provided for testing purposes only. Use at your own risk.'));
    $dependencies = array_keys($all_themes[$theme]->requires);
    $themes = array_merge([
        $theme,
    ], $dependencies);
    $is_experimental = function ($theme) use ($all_themes) {
        return isset($all_themes[$theme]) && $all_themes[$theme]->isExperimental();
    };
    $get_label = function ($theme) use ($all_themes) {
        return $all_themes[$theme]->info['name'];
    };
    $items = [];
    if (!empty($dependencies)) {
        // Display a list of required themes that have to be installed as well.
        $items[] = $this->formatPlural(count($dependencies), 'You must enable the @required theme to install @theme.', 'You must enable the @required themes to install @theme.', [
            '@theme' => $get_label($theme),
            // It is safe to implode this because theme names are not translated
            // markup and so will not be double-escaped.
'@required' => implode(', ', array_map($get_label, $dependencies)),
        ]);
    }
    // Add the list of experimental themes after any other messages.
    $items[] = $this->t('The following themes are experimental: @themes', [
        '@themes' => implode(', ', array_map($get_label, array_filter($themes, $is_experimental))),
    ]);
    $form['message'] = [
        '#theme' => 'item_list',
        '#items' => $items,
    ];
    return parent::buildForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.