123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?php
- require_once dirname(__FILE__) . '/includes/alpha.inc';
- require_once dirname(__FILE__) . '/includes/base.inc';
- require_once dirname(__FILE__) . '/includes/theme-settings-general.inc';
- require_once dirname(__FILE__) . '/includes/theme-settings-structure.inc';
-
- /**
- * Implements hook_form_system_theme_settings_alter()
- */
- function alpha_form_system_theme_settings_alter(&$form, &$form_state) {
- drupal_add_css(drupal_get_path('theme', 'alpha') . '/css/alpha-theme-settings.css', array('group' => CSS_THEME, 'weight' => 100));
-
- $theme = alpha_get_theme();
- $form_state['theme'] = $theme->theme;
- $form_state['regions'] = $theme->regions;
- $form_state['zones'] = $theme->zones;
-
- $form['alpha_settings'] = array(
- '#type' => 'vertical_tabs',
- '#weight' => -10,
- '#prefix' => t('<h3>Layout configuration</h3>'),
- );
-
- alpha_theme_settings_general($form, $form_state);
- alpha_theme_settings_structure($form, $form_state);
-
- $form['#validate'][] = 'alpha_theme_settings_form_validate';
- $form['#submit'][] = 'alpha_theme_settings_form_submit';
- }
- /**
- * Form element validation handler for replacing the value "_none" with NULL.
- */
- function alpha_theme_settings_validate_not_empty(&$element, &$form_state) {
- if ($element['#value'] == '_none') {
- form_set_value($element, NULL, $form_state);
- }
- }
- /**
- * Form element validation handler for validating the primary region setting for zones.
- */
- function alpha_theme_settings_validate_primary(&$element, &$form_state) {
- if ($element['#value'] != '_none') {
- $values = $form_state['values'];
-
- if ($values['alpha_region_' . $element['#value'] . '_zone'] != $element['#zone']) {
- form_set_value($element, NULL, $form_state);
- }
- else {
- $sum = 0;
-
- foreach ($form_state['regions'] as $region => $item) {
- if ($values['alpha_region_' . $region . '_zone'] == $element['#zone']) {
- $sum += $values['alpha_region_' . $region . '_columns'];
- $sum += $values['alpha_region_' . $region . '_prefix'];
- $sum += $values['alpha_region_' . $region . '_suffix'];
- }
- }
-
- if ($sum > $values['alpha_zone_' . $element['#zone'] . '_columns']) {
- form_error($element, t('You have specified the %region region as the primary region for the %zone zone but the summed region width is greater than the number of available columns for that zone.', array('%region' => $form_state['regions'][$element['#value']]['name'], '%zone' => $form_state['zones'][$element['#zone']]['name'])));
- }
- }
- }
- }
- /**
- * Form element validation handler for validating the region order manipulation setting for zones.
- */
- function alpha_theme_settings_validate_order(&$element, &$form_state) {
- if ($element['#value']) {
- $values = $form_state['values'];
- $sum = 0;
- foreach ($form_state['regions'] as $region => $item) {
- if ($values['alpha_region_' . $region . '_zone'] == $element['#zone']) {
- $sum += $values['alpha_region_' . $region . '_columns'];
- $sum += $values['alpha_region_' . $region . '_prefix'];
- $sum += $values['alpha_region_' . $region . '_suffix'];
- }
- }
- if ($sum > $values['alpha_zone_' . $element['#zone'] . '_columns']) {
- form_error($element, t('You have chosen to manipulate the region positioning of the %zone zone but the summed region width is greater than the number of available columns for that zone.', array('%zone' => $form_state['zones'][$element['#zone']]['name'])));
- }
- }
- }
- /**
- * Removes the vertical tab active tab from the values. It really doesn't
- * belong there!
- */
- function alpha_theme_settings_form_validate($form, &$form_state) {
- unset($form_state['values']['alpha_settings__active_tab']);
- }
- /**
- * Clears the cache for the theme settings upon form submission.
- */
- function alpha_theme_settings_form_submit($form, &$form_state) {
- alpha_cache_clear($form_state['theme'], (isset($form_state['delta']) ? $form_state['delta'] : NULL));
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @param $start
- * The number to start with.
- *
- * @param $end
- * The number to end with.
- *
- * @param $step
- * The size of a step.
- *
- * @return
- * An array of scale options.
- */
- function alpha_scale_options($start, $end, $step) {
- $options = array();
- foreach (range($start, $end, $step) as $number) {
- // Format the value to display with one decimal.
- $options[(string) $number] = number_format($number, 1);
- }
-
- return $options;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @return
- * An array of optional or responsive stylesheet options.
- */
- function alpha_css_options($css) {
- $output = array();
- foreach ($css as $key => $info) {
- $output[$key] = '<strong>' . check_plain($info['name']) . '</strong> (' . (isset($info['options']['media']) ? $info['options']['media'] : 'all') . ') - ' . $info['file'] . '<div class="description">' . $info['description'] . '</div>';
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @param $theme
- * The key (machin-readable name) of a theme.
- *
- * @see
- * hook_css_alter().
- *
- * @return
- * An array of stylesheets that can be disabled / excluded with
- * hook_css_alter().
- */
- function alpha_exclude_options($theme) {
- $output = array();
- foreach (alpha_retrieve_excludes($theme) as $key => $info) {
- if ($info['type'] == 'exclude') {
- $output[$key] = '<strong>' . basename($key) . '</strong> - ' . t('Defined by') . ' ' . $info['name'] . '<div class="description">' . $info['description'] . '</div>';
- }
- else {
- $output[$key] = '<strong>' . basename($key) . '</strong> (' . $info['media'] . ') - ' . t('Belongs to') . ' ' . $info['name'] . '<div class="description">' . $info['description'] . '</div>';
- }
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @return
- * An array of available grids.
- */
- function alpha_grid_options($grids) {
- $output = array();
- foreach ($grids as $key => $info) {
- $output[$key] = check_plain($info['name']);
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @param $grid
- * The name of a grid.
- *
- * @return
- * An array of available layouts.
- */
- function alpha_grid_layouts_options($grid) {
- $output = array();
- if (!empty($grid['layouts'])) {
- foreach ($grid['layouts'] as $key => $info) {
- $output[$key] = check_plain($info['name']);
- }
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @return
- * An array of available libraries.
- */
- function alpha_library_options($libraries) {
- $output = array();
- foreach ($libraries as $key => $info) {
- $output[$key] = check_plain($info['name']) . '<div class="description">' . $info['description'] . '</div>';
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @param $grid
- * The grid that you want to fetch the available containers for.
- *
- * @return
- * An array of available containers.
- */
- function alpha_container_options($grid) {
- $output = array();
- if (!empty($grid['columns'])) {
- foreach ($grid['columns'] as $count => $title) {
- $output[$count] = t('@count Columns', array('@count' => $count));
- }
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @param $max
- * The maximum number of columns that you want to cover.
- *
- * @return
- * An array of available columns counts.
- */
- function alpha_column_options($max = NULL) {
- $output = array();
- if (isset($max)) {
- foreach (range(0, $max) as $width) {
- $output[$width] = t('@width Columns', array('@width' => $width));
- }
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @return
- * An array of available zones.
- */
- function alpha_zone_options($zones) {
- $output = array();
- foreach ($zones as $key => $info) {
- $output[$key] = check_plain($info['name']);
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @return
- * An array of available regions.
- */
- function alpha_region_options($regions) {
- $output = array();
- foreach ($regions as $region => $item) {
- $output[$region] = $item['name'];
- }
-
- return $output;
- }
- /**
- * A helper function to return a proper options array for a form.
- *
- * @return
- * An array of available regions for a zone.
- */
- function alpha_zone_regions($zone, $regions) {
- $matches = array();
- foreach ($regions as $region => $info) {
- if ($zone == $info['zone']) {
- $matches[$region] = $info;
- }
- }
-
- return alpha_region_options($matches);
- }
|