You are here

public function PwaExtrasSettingsForm::buildForm in Progressive Web App 8

Same name and namespace in other branches
  1. 2.x modules/pwa_extras/src/Form/PwaExtrasSettingsForm.php \Drupal\pwa_extras\Form\PwaExtrasSettingsForm::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

modules/pwa_extras/src/Form/PwaExtrasSettingsForm.php, line 23

Class

PwaExtrasSettingsForm
PWA Extras admin settings form.

Namespace

Drupal\pwa_extras\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('pwa_extras.settings.apple');
  $form['apple'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Apple/IOS Specific Settings'),
    '#open' => TRUE,
  ];
  $mask_color = $config
    ->get('mask_color') ?: '#0678be';
  $form['apple']['touch_icons'] = [
    "#type" => 'checkboxes',
    "#title" => $this
      ->t('Touch Icons'),
    "#options" => str_replace('<', '&lt;', pwa_extras_apple_touch_icons($mask_color)),
    '#default_value' => $config
      ->get('touch_icons'),
  ];
  $form['apple']['mask_color'] = [
    "#type" => 'color',
    "#title" => $this
      ->t('Mask icon color'),
    "#description" => $this
      ->t('The color scheme of OS pinned tab mask icon.'),
    '#default_value' => $mask_color,
    '#states' => [
      'invisible' => [
        ':input[value="touch-icon-mask"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $site_name = $this
    ->config('pwa.config')
    ->get('site_name') ?: $this
    ->config('system.site')
    ->get('name');
  $color_select = $config
    ->get('color_select') ?: 'default';
  $form['apple']['meta_tags'] = [
    "#type" => 'checkboxes',
    "#title" => $this
      ->t('Meta Tags'),
    "#options" => str_replace('<', '&lt;', pwa_extras_apple_meta_tags($site_name, $color_select)),
    '#default_value' => $config
      ->get('meta_tags'),
  ];
  $form['apple']['color_select'] = [
    "#type" => 'select',
    "#title" => $this
      ->t('Select color for status-bar-style'),
    '#options' => [
      'default' => $this
        ->t('Default'),
      'black' => $this
        ->t('Black'),
      'black_translucent' => $this
        ->t('Black-translucent'),
    ],
    '#states' => [
      'invisible' => [
        ':input[value="meta-status-bar-style"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
    '#default_value' => $color_select,
  ];
  $form['apple']['home_screen_icons'] = [
    "#type" => 'checkboxes',
    "#title" => $this
      ->t('Add to homescreen icons'),
    "#options" => str_replace('<', '&lt;', pwa_extras_apple_home_screen_icons()),
    '#default_value' => $config
      ->get('home_screen_icons'),
  ];
  return parent::buildForm($form, $form_state);
}