예제 #1
0
/**
 * Implimentation of hook_form_system_theme_settings_alter()
 *
 * @param $form
 *   Nested array of form elements that comprise the form.
 *
 * @param $form_state
 *   A keyed array containing the current state of the form.
 */
function at_generator_form_system_theme_settings_alter(&$form, &$form_state) {

  // Set the theme name.
  $build_info = $form_state->getBuildInfo();
  $theme = $build_info['args'][0];

  // Instantiate our Theme info object.
  $themeInfo = new ThemeInfo($theme);
  $getThemeInfo = ($themeInfo->getThemeInfo('info'));

  // Common paths.
  $at_core_path  = drupal_get_path('theme', 'at_core');
  $at_generator_path = drupal_get_path('theme', 'at_generator');
  $subtheme_path = drupal_get_path('theme', $theme);

  $form['#attached']['library'][] = 'at_generator/at.generator';
  $form['generator'] = array('#type' => 'vertical_tabs');

  // Generator.
  include_once($at_generator_path . '/forms/generator.php');

  // Hide form items.
  $form['theme_settings']['#attributes']['class'] = array('visually-hidden');
  $form['logo']['#attributes']['class'] = array('visually-hidden');
  $form['favicon']['#attributes']['class'] = array('visually-hidden');

  // Modify the submit.
  $form['actions']['submit']['#value'] = t('Generate theme');
  $form['#validate'][] = 'at_generator_validate_generator';
  $form['#submit'][] = 'at_generator_submit_generator';

  include_once($at_generator_path . '/forms/generator_validate.php');
  include_once($at_generator_path . '/forms/generator_submit.php');
}
예제 #2
0
 /**
  * {@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;
 }
예제 #3
0
/**
 * Implimentation of hook_form_system_theme_settings_alter()
 *
 * @param $form
 *   Nested array of form elements that comprise the form.
 *
 * @param $form_state
 *   A keyed array containing the current state of the form.
 */
function at_core_form_system_theme_settings_alter(&$form, &$form_state) {

  // Set the theme name.
  $build_info = $form_state->getBuildInfo();
  $theme = $build_info['args'][0];

  // Instantiate our Theme info object.
  $themeInfo = new ThemeInfo($theme);
  $getThemeInfo = $themeInfo->getThemeInfo('info');

  // Get this themes config settings
  $config = \Drupal::config($theme . '.settings')->get('settings');

  // Common paths.
  $at_core_path  = drupal_get_path('theme', 'at_core');
  $subtheme_path = drupal_get_path('theme', $theme);

  // Path to save generated CSS files. We don't want this happening for at_core or the generator.
  if (isset($getThemeInfo['subtheme type']) && $getThemeInfo['subtheme type'] === 'adaptive_subtheme') {
    $directoryOperations = new DirectoryOperations();
    $generated_files_path = $directoryOperations->directoryPrepare($backup_file_path = array($subtheme_path, 'styles/css/generated'));
  }

  // Get the active themes regions so we can use this in
  // various other places.
  $theme_regions = system_region_list($theme, $show = REGIONS_VISIBLE);

  // Active themes active blocks
  $theme_blocks = entity_load_multiple_by_properties('block', ['theme' => $theme]);

  // Check for breakpoints module and set a warning and a flag to disable much of the theme settings if its not available
  $breakpoints_module = \Drupal::moduleHandler()->moduleExists('breakpoint');

  if ($breakpoints_module == TRUE) {
    $breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups();

    // Unset core breakpoint groups due to notices and other issues, until this is resolved:
    // SEE: https://www.drupal.org/node/2379283
    unset($breakpoint_groups['toolbar']);
    unset($breakpoint_groups['seven']);
    unset($breakpoint_groups['bartik']);

    // Set breakpoint options, we use these in layout and other extensions like Responsive menus.
    foreach ($breakpoint_groups as $group_key => $group_values) {
      $breakpoints[$group_key] = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup($group_key);
    }

    foreach($breakpoints as $group => $breakpoint_values)  {
      if ($breakpoint_values !== array()) {
        $breakpoint_options[$group] = $group;
      }
    }
  }
  else {
    drupal_set_message(t('Adaptivetheme requires the <b>Breakpoint module</b>. Open the <a href="!extendpage" target="_blank">Extend</a> page and enable Breakpoint.', array('!extendpage' => base_path() . 'admin/modules')), 'warning');
  }

  // Get node types (bundles).
  $node_types = node_type_get_types();

  // View or "Display modes", the search display mode is still problematic so we will exclude it for now,
  // please see: https://drupal.org/node/1166114
  //$node_view_modes = \Drupal::entityManager()->getViewModeOptions('node', TRUE);
  $node_view_modes = \Drupal::entityManager()->getViewModes('node');

  // Unset unwanted view modes
  unset($node_view_modes['rss']);
  unset($node_view_modes['search_index']);
  unset($node_view_modes['search_result']);

  // Set a class on the form for the current admin theme, note if this is set to "Default theme"
  // the result is always 0.
  $system_theme_config = \Drupal::config('system.theme');
  $admin_theme = $system_theme_config->get('admin');
  if (!empty($admin_theme)) {
    $admin_theme_class = 'admin-theme--' . Html::getClass($admin_theme);
    $form['#attributes'] = array('class' => array($admin_theme_class));
  }

  // Attached required CSS and JS.
  $form['#attached']['library'][] = 'at_core/at.appearance_settings';

  // AT Core
  if ($theme == 'at_core') {
    $form['at_core']['message'] = array(
      '#type' => 'container',
      '#markup' => t('AT Core has no configuration and cannot be used as a front end theme - it is a base them only. Use the <b>AT Theme Generator</b> to generate or clone a theme to get started.'),
    );

    // Hide form items.
    $form['theme_settings']['#attributes']['class'] = array('visually-hidden');
    $form['logo']['#attributes']['class'] = array('visually-hidden');
    $form['favicon']['#attributes']['class'] = array('visually-hidden');
    $form['actions']['#attributes']['class'] = array('visually-hidden');
  }

  // AT Subtheme
  if (isset($getThemeInfo['subtheme type'])) {

    if ($getThemeInfo['subtheme type'] !== 'adaptive_generator') {

      // Pass in the generated files path to values and settings.
      $form['at']['settings_generated_files_path'] = array(
        '#type' => 'hidden',
        '#value' => $generated_files_path,
      );

      // Extension settings.
      require_once($at_core_path . '/forms/ext/extension_settings.php');

      // Layouts.
      require_once($at_core_path . '/forms/layout/layouts.php');

      // Basic settings - move into details wrapper and collapse.
      $form['basic_settings'] = array(
        '#type' => 'details',
        '#title' => t('Basic Settings'),
        '#open' => FALSE,
      );

      $form['theme_settings']['#open'] = FALSE;
      $form['theme_settings']['#group'] = 'basic_settings';
      $form['logo']['#open'] = FALSE;
      $form['logo']['#group'] = 'basic_settings';
      $form['favicon']['#open'] = FALSE;
      $form['favicon']['#group'] = 'basic_settings';

      // buttons don't work with #group, move it the hard way.
      $form['actions']['#type'] = $form['basic_settings']['actions']['#type'] = 'actions';
      $form['actions']['submit']['#type'] = $form['basic_settings']['actions']['submit']['#type'] = 'submit';
      $form['actions']['submit']['#value'] = $form['basic_settings']['actions']['submit']['#value'] = t('Save basic settings');
      $form['actions']['submit']['#button_type'] = $form['basic_settings']['actions']['submit']['#button_type'] = 'primary';
      unset($form['actions']);
    }
  }

  // Modify the color scheme form.
  if (\Drupal::moduleHandler()->moduleExists('color')) {
    //include_once($at_core_path . '/forms/color/color_submit.php');
    if (isset($build_info['args'][0]) && ($theme = $build_info['args'][0]) && color_get_info($theme) && function_exists('gd_info')) {
      $form['#process'][] = 'at_core_make_collapsible';
    }
  }
}