'; } $output = ''; return $output . $extra; } /** * Implements theme_textarea() * * Add .form-control to textarea fields * * @param $variables * * @return string */ function hardwood_textarea($variables) { $element = $variables['element']; element_set_attributes($element, ['id', 'name']); _form_set_class($element, ['form-control']); $wrapper_attributes = [ 'class' => ['form-textarea-wrapper'], ]; // Add resizable behavior. if (!empty($element['#resizable'])) { drupal_add_library('system', 'drupal.textarea'); $wrapper_attributes['class'][] = 'resizable'; } $output = ''; $output .= '' . check_plain($element['#value']) . ''; $output .= ''; return $output; } /** * Implements theme_password() * * Add .form-control to password fields * * @param $variables * * @return string */ function hardwood_password($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'password'; element_set_attributes($element, ['id', 'name', 'size', 'maxlength']); _form_set_class($element, ['form-control']); return ''; } /** * Implements theme_form_search_block_form_alter() * * Alter the search form. * * @param $form */ function hardwood_form_search_block_form_alter(&$form) { $form['search_block_form']['#attributes']['placeholder'] = "Search..."; $form['search_block_form']['#field_prefix'] = FALSE; $form['search_block_form']['#field_suffix'] = FALSE; } /** * Implements theme_form_element(). * * Apply bootstrap wrappings and classes on all form elements. * * @param $variables * * @return string */ function hardwood_form_element($variables) { $element = &$variables['element']; // This function is invoked as theme wrapper, but the rendered form element // may not necessarily have been processed by form_builder(). //$element['#title_display'] = 'before'; // Add a class for disabled elements to facilitate cross-browser styling. if (!empty($element['#attributes']['disabled'])) { $attributes['class'][] = 'disabled'; } // 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'] = ['form-item']; if (!empty($element['#type'])) { $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-'); } if (!empty($element['#name'])) { $attributes['class'][] = 'form-item-' . strtr($element['#name'], [ ' ' => '-', '_' => '-', '[' => '-', ']' => '', ]); } $output = '' . "\n"; // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } if (!isset($element['#title_display'])) { $element['#title_display'] = 'before'; } $prefix = isset($element['#field_prefix']) ? '' . $element['#field_prefix'] . '' : ''; $suffix = isset($element['#field_suffix']) ? '' . $element['#field_suffix'] . '' : ''; switch ($element['#title_display']) { case 'before': case 'invisible': $output .= ' ' . theme('form_element_label', $variables); if (!empty($element['#description']) && isset($element['#type']) && in_array($element['#type'], [ 'radios', 'checkboxes', ])) { $output .= '
' . $element['#description'] . "
\n"; } $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'after': $output .= ' ' . $prefix . $element['#children'] . $suffix; $output .= ' ' . theme('form_element_label', $variables) . "\n"; if (!empty($element['#description']) && isset($element['#type']) && in_array($element['#type'], [ 'radios', 'checkboxes', ])) { $output .= '
' . $element['#description'] . "
\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']) && (!isset($element['#type']) || !in_array($element['#type'], [ 'radios', 'checkboxes', ]))) { $output .= '
' . $element['#description'] . "
\n"; } $output .= "\n"; return '
' . $output . '
'; } /** * Implements theme_button() * * @param $variables * * @return string */ function hardwood_button($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'submit'; element_set_attributes($element, ['id', 'name', 'value']); $element ['#attributes']['class'][] = 'form-' . $element ['#button_type']; if (!empty($element['#attributes']['disabled'])) { $element['#attributes']['class'][] = 'disabled'; } return ''; } /** * Alter status messages to use bootstrap alerts. * * @param $variables * * @return string */ function hardwood_status_messages($variables) { $display = $variables['display']; $output = ''; $status_heading = [ 'status' => t('Status message'), 'error' => t('Error message'), 'warning' => t('Warning message'), ]; foreach (drupal_get_messages($display) as $type => $messages) { switch ($type) { case "error": $cc = 'alert-danger'; break; case "warning": $cc = 'alert-warning'; break; case 'status': $cc = 'alert-info'; break; default: $cc = 'alert-info'; break; } $output .= "
\n"; if (!empty($status_heading[$type])) { $output .= '

' . $status_heading[$type] . "

\n"; } if (count($messages) > 1) { $output .= "
    \n"; foreach ($messages as $message) { $output .= '
  • ' . $message . "
  • \n"; } $output .= "
\n"; } else { $output .= reset($messages); } $output .= "
\n"; } return $output; } /** * Add the menu menu wrapper. * * @param $variables * * @return string */ function hardwood_menu_tree__primary(array &$variables) { return ''; } /** * Add the secondary menu wrapper. * * @param array $variables * * @return string */ function hardwood_menu_tree__secondary(array &$variables) { return ''; } /** * Returns HTML for a menu link and submenu. * * @param array $variables * An associative array containing: * - element: Structured array data for a menu link. * * @return string * The constructed HTML. * * @see theme_menu_link() * * @ingroup theme_functions */ function hardwood_menu_link__main_menu(array $variables) { $element = $variables['element']; $sub_menu = ''; $title = $element['#title']; $href = $element['#href']; $options = !empty($element['#localized_options']) ? $element['#localized_options'] : []; $attributes = !empty($element['#attributes']) ? $element['#attributes'] : []; $attributes['class'][] = 'nav-item'; $options['attributes']['class'][] = 'nav-link'; if ($element['#below']) { // Prevent dropdown functions from being added to management menu so it // does not affect the navbar module. if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) { $sub_menu = drupal_render($element['#below']); } elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) { // Add our own wrapper. //$element['#below']['#theme_wrappers'] = array('menu_tree__sub_menu'); $sub_menu = ''; // Generate as standard dropdown. $attributes['class'][] = 'dropdown'; $options['html'] = TRUE; // Set dropdown trigger element to # to prevent inadvertant page loading // when a submenu link is clicked. $options['attributes']['class'][] = 'dropdown-toggle'; $options['attributes']['data-toggle'] = 'dropdown'; } } return '' . l($title, $href, $options) . $sub_menu . "\n"; } /** * @param array $variables * * @return string * @see \theme_menu_link() */ function hardwood_menu_link__user_menu(array &$variables) { return hardwood_menu_link__main_menu($variables); } /** * Generates dropdown menu wrapper. * * @param array $variables * * @return string */ function hardwood_menu_tree_link__sub_menu(array &$variables) { return ''; } /** * Create themeable objects. * * Implements hook_theme() * * @param array $existing * @param string $type * @param string $theme * @param string $path * * @return array * * @see \hook_theme() */ function hardwood_theme($existing, $type, $theme, $path) { return [ 'survey_modal' => [ 'template' => 'other/survey_modal', 'path' => $path . '/templates', ], ]; } /** * Implements hook_theme_registry_alter(). * * @param $theme_registry */ function hardwood_theme_registry_alter(&$theme_registry) { $path = path_to_theme(); // Tell the theme system to look in the "templates" subdirectory within our theme directory // Force tripal_blast to use our blast_report template $theme_registry['show_blast_report']['theme paths'] = [0 => $path . '/templates']; $theme_registry['show_blast_report']['theme path'] = $path . '/templates'; $theme_registry['show_blast_report']['path'] = $path . '/templates'; $theme_registry['show_blast_report']['template'] = 'blast/blast_report'; $theme_registry['trpdownload_page']['path'] = $path . '/templates'; $theme_registry['trpdownload_page']['template'] = 'other/generic_download_page'; $theme_registry['analysis_expression_plot']['path'] = $path . '/templates'; $theme_registry['analysis_expression_plot']['template'] = 'tripal/tripal_analysis_expression.analysis'; foreach ($theme_registry as $key => $theme) { if (isset($theme['template']) && strpos($theme['template'], 'node--chado-generic') !== FALSE) { $theme_registry[$key]['path'] = $path . '/templates'; $theme_registry[$key]['template'] = 'tripal/node--chado-generic'; } } } /** * @param $form * @param $form_state */ function hardwood_form_website_search_box_form_alter(&$form, &$form_state) { hardwood_form_tripal_elasticsearch_site_wide_search_form_alter($form, $form_state); } /** * Alter the search form to use Bootstrap fields. * * @param $form * @param $form_state */ function hardwood_form_tripal_elasticsearch_site_wide_search_form_alter(&$form, &$form_state) { $input_group_classes = "input-group elasticsearch-search-input"; $height = 38; if (drupal_is_front_page()) { $input_group_classes .= ' input-group-lg'; $height = 51; } $form['container']['#attributes']['class'][] = $input_group_classes; $form['container']['search_box']['#theme_wrappers'] = []; unset($form['container']['search_box']['#size']); $form['container']['search_box']['#attributes']['placeholder'] = 'Site Wide Search'; $form['container']['search_box']['#attributes']['style'] = "height: {$height}px;"; $form['container']['submit']['#prefix'] = '
'; $form['container']['submit']['#suffix'] = '
'; } /** * Add `form-control` class to the category