/sites/all/themes/radix/template.php
PHP | 376 lines | 230 code | 38 blank | 108 comment | 45 complexity | 01ebed3eb865c5a1e4b3bde6a9f44918 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
- <?php
- /**
- * Implementation of template_preprocess_html()
- */
- function radix_preprocess_html(&$variables) {
- // add meta for Bootstrap Responsive
- // <meta name="viewport" content="width=device-width, initial-scale=1.0">
- $element = array(
- '#tag' => 'meta',
- '#attributes' => array(
- 'name' => 'viewport',
- 'content' => 'width=device-width, initial-scale=1.0',
- ),
- );
- drupal_add_html_head($element, 'bootstrap_responsive');
- }
- /**
- * Implements hook_js_alter().
- */
- function radix_js_alter(&$js) {
- //$js['misc/jquery.js']['data'] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js';
- }
- /**
- * Implements hook_css_alter().
- */
- function radix_css_alter(&$css) {
- if (isset($css['sites/all/modules/panopoly/panopoly_admin/panopoly-admin.css'])) {
- unset($css['sites/all/modules/panopoly/panopoly_admin/panopoly-admin.css']);
- }
- }
- /**
- * Implements template_preprocess_page().
- */
- function radix_preprocess_page(&$variables) {
- // determine if the page is rendered using panels
- $variables['is_panel'] = FALSE;
- if (module_exists('page_manager') && sizeof(page_manager_get_current_page())) {
- $variables['is_panel'] = TRUE;
- }
- // Add search_form to theme
- $variables['search_form'] = '';
- if (module_exists('search') && user_access('search content')) {
- $search_box_form = drupal_get_form('search_form');
- $search_box_form['basic']['keys']['#title'] = '';
- $search_box_form['basic']['keys']['#attributes'] = array('placeholder' => 'Search');
- $search_box_form['basic']['keys']['#attributes']['class'][] = 'search-query';
- $search_box_form['basic']['submit']['#value'] = t('Search');
- $search_box_form['#attributes']['class'][] = 'navbar-form';
- $search_box_form['#attributes']['class'][] = 'pull-right';
- $search_box = drupal_render($search_box_form);
- $variables['search_form'] = (user_access('search content')) ? $search_box : NULL;
- }
- // Format and add main menu to theme
- $main_menu_tree = menu_tree_all_data('main-menu');
- $variables['main_menu'] = menu_tree_output($main_menu_tree);
- // Format and add footer menu to theme
- $footer_menu_tree = menu_tree_all_data('menu-footer-menu');
- $variables['footer_menu'] = menu_tree_output($footer_menu_tree);
- }
- /**
- * Implements theme_table().
- */
- function radix_table($variables) {
- // add default classes to table elements
- $variables['attributes']['class'] = (isset($variables['attributes']['class'])) ? $variables['attributes']['class'] : array();
- $variables['attributes']['class'] = (is_array($variables['attributes']['class'])) ? $variables['attributes']['class'] : array($variables['attributes']['class']);
- $variables['attributes']['class'] = array_merge($variables['attributes']['class'], array('table', 'table-striped', 'table-bordered'));
- $header = $variables['header'];
- $rows = $variables['rows'];
- $attributes = $variables['attributes'];
- $caption = $variables['caption'];
- $colgroups = $variables['colgroups'];
- $sticky = $variables['sticky'];
- $empty = $variables['empty'];
- // Add sticky headers, if applicable.
- if (count($header) && $sticky) {
- drupal_add_js('misc/tableheader.js');
- // Add 'sticky-enabled' class to the table to identify it for JS.
- // This is needed to target tables constructed by this function.
- $attributes['class'][] = 'sticky-enabled';
- }
- $output = '<table' . drupal_attributes($attributes) . ">\n";
- if (isset($caption)) {
- $output .= '<caption>' . $caption . "</caption>\n";
- }
- // Format the table columns:
- if (count($colgroups)) {
- foreach ($colgroups as $number => $colgroup) {
- $attributes = array();
- // Check if we're dealing with a simple or complex column
- if (isset($colgroup['data'])) {
- foreach ($colgroup as $key => $value) {
- if ($key == 'data') {
- $cols = $value;
- }
- else {
- $attributes[$key] = $value;
- }
- }
- }
- else {
- $cols = $colgroup;
- }
- // Build colgroup
- if (is_array($cols) && count($cols)) {
- $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
- $i = 0;
- foreach ($cols as $col) {
- $output .= ' <col' . drupal_attributes($col) . ' />';
- }
- $output .= " </colgroup>\n";
- }
- else {
- $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
- }
- }
- }
- // Add the 'empty' row message if available.
- if (!count($rows) && $empty) {
- $header_count = 0;
- foreach ($header as $header_cell) {
- if (is_array($header_cell)) {
- $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
- }
- else {
- $header_count++;
- }
- }
- $rows[] = array(array(
- 'data' => $empty,
- 'colspan' => $header_count,
- 'class' => array('empty', 'message'),
- ));
- }
- // Format the table header:
- if (count($header)) {
- $ts = tablesort_init($header);
- // HTML requires that the thead tag has tr tags in it followed by tbody
- // tags. Using ternary operator to check and see if we have any rows.
- $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
- foreach ($header as $cell) {
- $cell = tablesort_header($cell, $header, $ts);
- $output .= _theme_table_cell($cell, TRUE);
- }
- // Using ternary operator to close the tags based on whether or not there are rows
- $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
- }
- else {
- $ts = array();
- }
- // Format the table rows:
- if (count($rows)) {
- $output .= "<tbody>\n";
- $flip = array(
- 'even' => 'odd',
- 'odd' => 'even',
- );
- $class = 'even';
- foreach ($rows as $number => $row) {
- $attributes = array();
- // Check if we're dealing with a simple or complex row
- if (isset($row['data'])) {
- foreach ($row as $key => $value) {
- if ($key == 'data') {
- $cells = $value;
- }
- else {
- $attributes[$key] = $value;
- }
- }
- }
- else {
- $cells = $row;
- }
- if (count($cells)) {
- // Add odd/even class
- if (empty($row['no_striping'])) {
- $class = $flip[$class];
- $attributes['class'][] = $class;
- }
- // Build row
- $output .= ' <tr' . drupal_attributes($attributes) . '>';
- $i = 0;
- foreach ($cells as $cell) {
- $cell = tablesort_cell($cell, $header, $ts, $i++);
- $output .= _theme_table_cell($cell);
- }
- $output .= " </tr>\n";
- }
- }
- $output .= "</tbody>\n";
- }
- $output .= "</table>\n";
- return $output;
- }
- /**
- * Returns HTML for a button form element.
- *
- * @param $variables
- * An associative array containing:
- * - element: An associative array containing the properties of the element.
- * Properties used: #attributes, #button_type, #name, #value.
- *
- * @ingroup themeable
- */
- function radix_button($variables) {
- $element = $variables['element'];
- $element['#attributes']['type'] = 'submit';
- element_set_attributes($element, array('id', 'name', 'value'));
- $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
- $element['#attributes']['class'][] = 'btn';
- if (!empty($element['#attributes']['disabled'])) {
- $element['#attributes']['class'][] = 'form-button-disabled';
- }
- // add a btn-primary class if submit button
- if ($element['#parents'][0] == 'submit') {
- $element['#attributes']['class'][] = 'btn-primary';
- }
- return '<input' . drupal_attributes($element['#attributes']) . ' />';
- }
- /**
- * Implements theme_menu_link().
- */
- function radix_link($variables) {
- $icons = '';
- if (isset($variables['options']['attributes']['class']) && is_array($variables['options']['attributes']['class'])) {
- $css_classes = $variables['options']['attributes']['class'];
- if ($icon_classes = preg_grep('/^icon\-.*/', $css_classes)) {
- // render an icon for each class
- foreach ($icon_classes as $icon_class) {
- $icons .= '<i class="' . $icon_class . '"></i>';
- }
- // unset icon classes for attributes to prevent double rendering
- $variables['options']['attributes']['class'] = array_diff($css_classes, $icon_classes);
- }
- }
- return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . $icons . '<span>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</span>' . '</a>';
- }
- /**
- * Returns HTML for a form element.
- *
- * Each form element is wrapped in a DIV container having the following CSS
- * classes:
- * - form-item: Generic for all form elements.
- * - form-type-#type: The internal element #type.
- * - form-item-#name: The internal form element #name (usually derived from the
- * $form structure and set via form_builder()).
- * - form-disabled: Only set if the form element is #disabled.
- *
- * In addition to the element itself, the DIV contains a label for the element
- * based on the optional #title_display property, and an optional #description.
- *
- * The optional #title_display property can have these values:
- * - before: The label is output before the element. This is the default.
- * The label includes the #title and the required marker, if #required.
- * - after: The label is output after the element. For example, this is used
- * for radio and checkbox #type elements as set in system_element_info().
- * If the #title is empty but the field is #required, the label will
- * contain only the required marker.
- * - invisible: Labels are critical for screen readers to enable them to
- * properly navigate through forms but can be visually distracting. This
- * property hides the label for everyone except screen readers.
- * - attribute: Set the title attribute on the element to create a tooltip
- * but output no label element. This is supported only for checkboxes
- * and radios in form_pre_render_conditional_form_element(). It is used
- * where a visual label is not needed, such as a table of checkboxes where
- * the row and column provide the context. The tooltip will include the
- * title and required marker.
- *
- * If the #title property is not set, then the label and any required marker
- * will not be output, regardless of the #title_display or #required values.
- * This can be useful in cases such as the password_confirm element, which
- * creates children elements that have their own labels and required markers,
- * but the parent element should have neither. Use this carefully because a
- * field without an associated label can cause accessibility challenges.
- *
- * @param $variables
- * An associative array containing:
- * - element: An associative array containing the properties of the element.
- * Properties used: #title, #title_display, #description, #id, #required,
- * #children, #type, #name.
- *
- * @ingroup themeable
- */
- function radix_form_element($variables) {
- $element = &$variables['element'];
- // This is also used in the installer, pre-database setup.
- $t = get_t();
- // This function is invoked as theme wrapper, but the rendered form element
- // may not necessarily have been processed by form_builder().
- $element += array(
- '#title_display' => 'before',
- );
- // Add element #id for #type 'item'.
- if (isset($element['#markup']) && !empty($element['#id'])) {
- $attributes['id'] = $element['#id'];
- }
- // Add element's #type and #name as class to aid with JS/CSS selectors.
- $attributes['class'] = array('form-item');
- if (!empty($element['#type'])) {
- $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
- }
- if (!empty($element['#name'])) {
- $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
- }
- // Add a class for disabled elements to facilitate cross-browser styling.
- if (!empty($element['#attributes']['disabled'])) {
- $attributes['class'][] = 'form-disabled';
- }
- $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
- // If #title is not set, we don't display any label or required marker.
- if (!isset($element['#title'])) {
- $element['#title_display'] = 'none';
- }
- $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
- $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
- switch ($element['#title_display']) {
- case 'before':
- case 'invisible':
- $output .= ' ' . theme('form_element_label', $variables);
- $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
- break;
- case 'after':
- $output .= ' ' . $prefix . $element['#children'] . $suffix;
- $output .= ' ' . theme('form_element_label', $variables) . "\n";
- break;
- case 'none':
- case 'attribute':
- // Output no label and no required marker, only the children.
- $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
- break;
- }
- if (!empty($element['#description'])) {
- $output .= '<div class="description">' . $element['#description'] . "</div>\n";
- }
- $output .= "</div>\n";
- return $output;
- }