<?php /** * @file * Generator settings. * // TODO skins are disabled until further testing and dev. */ use Drupal\at_core\Theme\ThemeSettingsInfo; $themeSettingsInfo = new ThemeSettingsInfo(); $sourceThemeOptions = $themeSettingsInfo->baseThemeOptions(); $form['generate'] = array('#type' => 'details', '#title' => 'Generator', '#tree' => TRUE, '#group' => 'generator'); // Friendly name. $form['generate']['generate_friendly_name'] = array('#type' => 'textfield', '#title' => t('Theme name'), '#maxlength' => 50, '#size' => 30, '#required' => TRUE, '#default_value' => '', '#description' => t('A unique "friendly" name. Letters, spaces and underscores only - numbers and all other chars are stripped or converted.')); // Machine name. $form['generate']['generate_machine_name'] = array('#type' => 'machine_name', '#maxlength' => 50, '#size' => 30, '#title' => t('Machine name'), '#required' => TRUE, '#field_prefix' => '', '#default_value' => '', '#machine_name' => array('exists' => array($themeSettingsInfo, 'themeNameExists'), 'source' => array('generate', 'generate_friendly_name'), 'label' => t('Machine name'), 'replace_pattern' => '[^a-z_]+', 'replace' => '_')); $generate_type_options = array('standard' => t('Standard kit')); if (!empty($sourceThemeOptions)) { $generate_type_options = array('standard' => t('Standard kit'), 'clone' => t('Clone')); } $form['generate']['generate_type'] = array('#type' => 'select', '#title' => t('Type'), '#required' => TRUE, '#options' => $generate_type_options); $form['generate']['generate_type_description_standard_kit'] = array('#type' => 'container', '#markup' => t('Standard kit includes an advanced layout and is designed to fully support the UIKit and Color module (both optional).'), '#attributes' => array('class' => array('generate-type__description')), '#states' => array('visible' => array('select[name="generate[generate_type]"]' => array('value' => 'standard')))); //$form['generate']['generate_type_description_minimal_kit'] = array( // '#type' => 'container', // '#markup' => t('Minimal kit includes Drupal core regions only, no UIKit styles, no Color module option. This is a very basic "layout only" theme.'), // '#attributes' => array('class' => array('generate-type__description')), // '#states' => array( // 'visible' => array('select[name="generate[generate_type]"]' => array('value' => 'minimal')), // ), //); $form['generate']['generate_clone_source'] = array('#type' => 'select', '#title' => t('Clone source'), '#options' => $sourceThemeOptions, '#default_value' => '', '#description' => t('Clones are direct copies of existing sub-themes. Use a unique name.'), '#states' => array('visible' => array('select[name="generate[generate_type]"]' => array('value' => 'clone')))); //$form['generate']['generate_skin_base'] = array(
/** * {@inheritdoc} */ public function getCompatibleLayout() { $layout_compatible_data = array(); // Caching the data here appears to shave about 50ms off page execution. // TODO - needs performance testing? if ($cache = \Drupal::cache()->get($this->theme_name . ':compatiblelayout')) { $layout_compatible_data = $cache->data; } else { // Get all base themes for the current theme, any one of these could // have a compatible layout. $themeSettingsInfo = new ThemeSettingsInfo($this->theme_name); $providers = $themeSettingsInfo->baseThemeInfo('base_themes'); // Unset at_core and classy, these never have a layout. unset($providers['stable']); unset($providers['classy']); unset($providers['at_core']); $ThemeInfo = new ThemeInfo($this->theme_name); $info_layout = $ThemeInfo->getThemeInfo('info'); // This is critical to restrict the theme to use only the layout specified // in the info file, because there can be many layouts throughout the // base_theme tree, but not all might be compatible and a theme can only // use one layout at a time. if (!empty($info_layout['layout'])) { $compatible_layout = $info_layout['layout']; } else { drupal_set_message('"layout" not declared in info file. Adaptivetheme requires a compatible layout to be declared in your theme info file e.g. "layout: site-builder". Add the declaration, clear the cache and try again.'); } // Push the current theme into the array - if it has a layout, use it. $providers[$this->theme_name] = $this->theme_name; // Get the configuration data for layout markup and CSS. foreach ($providers as $key => $provider_name) { $this_layout[$key] = new Layout($key, $compatible_layout); $layout_markup[$key] = $this_layout[$key]->getLayoutMarkup(); $layout_css[$key] = $this_layout[$key]->getLayoutCSS(); // Push additional information about the layout, useful later on. if (isset($layout_markup[$key]['rows'])) { $layout_markup[$key]['layout'] = $compatible_layout; $layout_markup[$key]['layout_provider'] = $key; } if (isset($layout_css[$key]['css'])) { $layout_css[$key]['layout'] = $compatible_layout; $layout_css[$key]['layout_provider'] = $key; } } // Remove empty values and get the last item values, this is our layout // and css configuration.this only really matters if the exact same layout // has been duplicated, which might happen if a themer is customizing the // layout for a particular sub-theme and does not bother to change the // name of the layout (and reflects that change in the themes info file). $filter_layout_config = array_filter($layout_markup); $filter_css_config = array_filter($layout_css); // Split end from array_filter to avoid a strict pass by reference warning. $layout_compatible_data['layout_config'] = end($filter_layout_config); $layout_compatible_data['css_config'] = end($filter_css_config); // Push the layout name into the array for access during form building. $layout_compatible_data['layout_name'] = $compatible_layout; if (!empty($layout_compatible_data)) { \Drupal::cache()->set($this->theme_name . ':compatiblelayout', $layout_compatible_data); } } return $layout_compatible_data; }