';
}
$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 .= '';
$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 '' . $variables['tree'] . ' ';
}
/**
* Add the secondary menu wrapper.
*
* @param array $variables
*
* @return string
*/
function hardwood_menu_tree__secondary(array &$variables) {
return '' . $variables['tree'] . ' ';
}
/**
* 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 element in the contact
* page.
*
* @param $form
* @param $form_state
*/
function hardwood_form_contact_site_form_alter(&$form, &$form_state) {
$form['cid']['#attributes']['class'][] = 'form-control';
}
/**
* Alter or add JS files to pages.
*
* @param $javascript
*/
function hardwood_js_alter(&$javascript) {
unset($javascript['misc/collapse.js']);
drupal_add_js(drupal_get_path('theme', 'hardwood') . '/dist/js/collapse.js',
[]);
}
/**
* Implements theme_progress_bar()
*
* Changes the progress bar markup to match BS4
*
* @param $variables
*
* @return string
*/
function hardwood_progress_bar($variables) {
$output = "";
$output .= "
{$variables['percent']}%
";
$output .= "
";
$output .= '' . $variables['message'] . '
';
return $output;
}
function hardwood_form_node_form_alter(&$form, &$form_state, $form_id) {
if (!isset($form['#node']->nid)) {
return;
}
$form['theme_options'] = [
'#type' => 'fieldset',
'#title' => t('Theme Options'),
'#access' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#tree' => TRUE,
];
$form['theme_options']['display_card'] = [
'#type' => 'checkbox',
'#title' => t('Display box borders around page content'),
'#default_value' => FALSE,
];
$nid = $form['#node']->nid;
$cards = variable_get('hardwood_page_cards');
if (is_array($cards)) {
$form['theme_options']['display_card']['#default_value'] = !isset($cards[$nid]);
}
$form['#submit'][] = 'hardwood_from_node_submit';
}
function hardwood_from_node_submit(&$form, &$form_state) {
if (!isset($form['#node']->nid)) {
return;
}
$values = $form_state['values'];
$nid = $form['#node']->nid;
$cards = variable_get('hardwood_page_cards');
if (!$values['theme_options']['display_card']) {
if (is_array($cards)) {
$cards[$nid] = $nid;
}
else {
$cards[$nid] = [$nid];
}
}
else {
if (is_array($cards)) {
if (isset($cards[$nid])) {
unset($cards[$nid]);
}
}
}
variable_set('hardwood_page_cards', $cards);
}
function hardwood_add_help_variables(&$variables) {
if (function_exists('hardwoods_help_get_help_menu_items')) {
$variables['help_items'] = hardwoods_help_get_help_menu_items();
}
}
function hardwood_form_blast_ui_per_blast_program_form_alter(&$form, &$form_state) {
$query_type = arg(2);//strtolower($form_state['build_info']['args'][0]);
if (strstr(strtolower($query_type), 'nucleotide') === FALSE) {
return;
}
$form['B']['DB']['#prefix'] = '';
$form['B']['DB']['#suffix'] = '
';
$options = $form['B']['DB']['SELECT_DB']['#options'];
$transcripts = [];
$scaffolds = [];
foreach ($options as $node_id => $option) {
if ($option === 'select a dataset') {
continue;
}
$option = strtolower($option);
if (strstr($option, 'transcript') !== FALSE || strstr($option, 'unigene') !== FALSE) {
$transcripts[$node_id] = $option;
}
else {
$scaffolds[$node_id] = $option;
}
}
$form['B']['DB']['SELECT_DB']['#options'] = [
'Full Genomes/Scaffolds' => $scaffolds,
'Transcripts/Unigenes' => $transcripts,
];
}