Some started code

  $form['subtheme']['subtheme_machine_name'] = [
    '#type' => 'machine_name',
    '#title' => t('Subtheme name'),
    '#default_value' => theme_get_setting('subtheme_machine_name'),
    '#description' => t("Use lowercase characters, numbers and underscores. Name must start with a letter."),
    '#machine_name' => [
      'source' => ['subtheme_name'],
      'exists' => 'bootstrap4_form_system_theme_settings_subtheme_exists',
      'replace_pattern' => '[^a-z0-9-]+',
      'replace' => '_',
      'error' => t('Theme already exists.'),
    ],
  ];

/**
 * Checks if a theme machine name is taken.
 *
 * @param string $value
 *   The machine name, not prefixed.
 * @param array $element
 *   An array containing the structure of the 'field_name' element.
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 *   The current state of the form.
 *
 * @return bool
 *   Whether or not the field machine name is taken.
 */
function bootstrap4_form_system_theme_settings_subtheme_exists($value, $element, FormStateInterface $form_state) {
  return in_array($value, ['bootstrap', 'bootstrap4', 'claro', 'bartik', 'seven']);
}

Comments

VladimirAus created an issue. See original summary.

vladimiraus’s picture

Status: Active » Closed (outdated)