You are here

public function FormModeThemeSwitcherForm::buildFormPerFormMode in Form mode manager 8.2

Build form element per form modes linked by given entity type.

Parameters

array $form: An associative array containing the structure of the form.

array $form_mode: The form mode definition.

string $entity_type_id: The entity type ID of entity.

Return value

$this|false The form Object.

Overrides FormModeManagerFormBase::buildFormPerFormMode

File

modules/form_mode_theme_switcher/src/Form/FormModeThemeSwitcherForm.php, line 135

Class

FormModeThemeSwitcherForm
Configure Form for Form Mode Manager theme switcher settings.

Namespace

Drupal\form_mode_manager_theme_switcher\Form

Code

public function buildFormPerFormMode(array &$form, array $form_mode, $entity_type_id) {
  $form_mode_id = str_replace('.', '_', $form_mode['id']);
  $form['theme_switcher_form_mode_settings'][$entity_type_id]['form_modes'][$form_mode_id] = [
    '#type' => 'details',
    '#title' => $form_mode['label'],
    '#description' => $this
      ->t('Configure the theme negotiation for specific form mode (<b>@form_mode_id</b>)', [
      '@form_mode_id' => $form_mode['label'],
    ]),
    '#open' => TRUE,
  ];
  $form['theme_switcher_form_mode_settings'][$entity_type_id]['form_modes'][$form_mode_id]["{$form_mode['id']}_theme_type"] = [
    '#title' => $this
      ->t('Default themes'),
    '#type' => 'select',
    '#options' => $this
      ->getAvailableThemeTypeOptions(),
    '#default_value' => $this->settings
      ->get("type.{$form_mode_id}"),
    '#description' => $this
      ->t("Select the type of theme you want to use. You can choose the themes defined by the drupal configuration (default or admin) or select one with the 'custom' option"),
    '#weight' => 0,
    '#empty_value' => '_none',
    '#empty_option' => $this
      ->t('- Default settings -'),
  ];
  $form['theme_switcher_form_mode_settings'][$entity_type_id]['form_modes'][$form_mode_id]["{$form_mode['id']}_theme_form_mode"] = [
    '#title' => $this
      ->t('Specific active theme'),
    '#type' => 'select',
    '#options' => $this
      ->getActiveThemeOptions(),
    '#default_value' => $this->settings
      ->get("form_mode.{$form_mode_id}"),
    '#description' => $this
      ->t('Select a theme from the available active themes list.'),
    '#weight' => 0,
    '#states' => [
      'visible' => [
        ":input[name=\"{$form_mode['id']}_theme_type\"]" => [
          'value' => '_custom',
        ],
      ],
    ],
  ];
  return $this;
}