diff --git a/sites/all/themes/unl_wdn/includes/form.inc b/sites/all/themes/unl_wdn/includes/form.inc index 13eb07c08a65d049d5bb42fbb9db18f16786ad25..f91c5c8d975036edb360a95a0362818a1f57441a 100644 --- a/sites/all/themes/unl_wdn/includes/form.inc +++ b/sites/all/themes/unl_wdn/includes/form.inc @@ -1,129 +1,162 @@ <?php -function unl_wdn_form($variables) -{ - if (!theme_get_setting('zen_forms')) { - return theme_form($variables); - } +/** + * @file + * Hooks to support UNL_WDN zenform styling and markup + */ - $output = <<<EOF +/** + * Implements theme_form(). + */ +function unl_wdn_form($variables) { + $output = <<<EOF <script type="text/javascript"> -//<![CDATA[ - WDN.jQuery(document).ready(function(){ - WDN.initializePlugin('zenform'); - }); -//]]> +// <![CDATA[ + WDN.jQuery(document).ready(function(){WDN.initializePlugin('zenform');}); +// ]]> </script> - EOF; - - $element = $variables['element']; - $element['#attributes']['class'][] = 'zenform'; - $action = $element['#action'] ? 'action="' . check_url($element['#action']) . '" ' : ''; - $output .= PHP_EOL . '<!-- FORM STARTS HERE -->' . PHP_EOL . PHP_EOL; - $output .= '<form ' . $action . ' accept-charset="UTF-8" method="' . $element['#method'] . '" id="' . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . ">\n" . $element['#children'] . "\n</form>\n"; - $output .= PHP_EOL . PHP_EOL . '<!-- FORM ENDS HERE -->' . PHP_EOL; - return $output; -} -function unl_wdn_fieldset($variables) -{ - if (!theme_get_setting('zen_forms')) { - return theme_fieldset($variables); - } - - $element = $variables['element']; - - $output = '<fieldset' . drupal_attributes($element['#attributes']) . '>'; - if (!empty($element['#title'])) { - // Always wrap fieldset legends in a SPAN for CSS positioning. - $output .= '<legend>' . $element['#title'] . '</legend>'; - } - if (!empty($element['#description'])) { - $output .= '<div>' . $element['#description'] . '</div>'; - } - $output .= '<ol>' . $element['#children'] . '</ol>'; - if (isset($element['#value'])) { - $output .= $element['#value']; - } - $output .= "</fieldset>\n"; - return $output; + $element = $variables['element']; + $element['#attributes']['class'][] = 'zenform'; + $action = $element['#action'] ? 'action="' . check_url($element['#action']) . '" ' : ''; + $output .= PHP_EOL . '<!-- FORM STARTS HERE -->' . PHP_EOL . PHP_EOL; + $output .= '<form ' . $action . ' accept-charset="UTF-8" method="' . $element['#method'] . '" id="' . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . ">\n" . $element['#children'] . "\n</form>\n"; + $output .= PHP_EOL . PHP_EOL . '<!-- FORM ENDS HERE -->' . PHP_EOL; + return $output; } -function unl_wdn_form_element($variables) -{ - if (!theme_get_setting('zen_forms')) { - return theme_form_element($variables); - } - - $element = $variables['element']; - // This is also used in the installer, pre-database setup. - $t = get_t(); - - // 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(); - $output = '<li' . 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': - $output .= ' ' . theme('form_element_label', $variables); - $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; - break; - - case 'invisible': - 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; - } - +/** + * Implements theme_fieldset(). + */ +function unl_wdn_fieldset($variables) { + $element = $variables['element']; + + if (count($element['#parents']) > 2) { + $output = '<li>'; + } + else { + $output = ''; + } + + $output .= '<fieldset' . drupal_attributes($element['#attributes']) . '>'; + if (!empty($element['#title'])) { + // Always wrap fieldset legends in a SPAN for CSS positioning. + $output .= '<legend>' . $element['#title'] . '</legend>'; + } + if (!empty($element['#description'])) { + $output .= '<div>' . $element['#description'] . '</div>'; + } + $output .= '<ol>' . $element['#children'] . '</ol>'; + if (isset($element['#value'])) { + $output .= $element['#value']; + } + $output .= "</fieldset>\n"; + if (count($element['#parents']) > 2) { $output .= "</li>\n"; - - return $output; + } + return $output; +} + +/** + * Implements theme_form_element(). + */ +function unl_wdn_form_element($variables) { + $element = $variables['element']; + // This is also used in the installer, pre-database setup. + $t = get_t(); + + // 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(); + $output = '<li' . 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': + $output .= ' ' . theme('form_element_label', $variables); + $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; + break; + + case 'invisible': + 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; + } + + $output .= "</li>\n"; + + return $output; } +/** + * Implements theme_form_element_label(). + */ +function unl_wdn_form_element_label($variables) { + $element = $variables['element']; + + if (!$element['#title']) { + return ''; + } -function unl_wdn_form_element_label($variables) -{ - if (!theme_get_setting('zen_forms')) { - return theme_form_element_label($variables); - } - - $element = $variables['element']; - - if (!$element['#title']) { - return ''; - } - - $attributes = array(); - if (!empty($element['#id'])) { - $attributes['for'] = $element['#id']; - } - - $output = '<label ' . drupal_attributes($attributes) . '>' . PHP_EOL - . ($element['#required'] ? '<span class="required">*</span>' . PHP_EOL : '') - . filter_xss_admin($element['#title']) . PHP_EOL - . (isset($element['#description']) ? '<span class="helper">' . $element['#description'] . '</span>' . PHP_EOL : '') - .'</label>' . PHP_EOL; - - return $output; + $attributes = array(); + if (!empty($element['#id'])) { + $attributes['for'] = $element['#id']; + } + + $output = '<label ' . drupal_attributes($attributes) . '>' . PHP_EOL + . ($element['#required'] ? '<span class="required">*</span>' . PHP_EOL : '') + . filter_xss_admin($element['#title']) . PHP_EOL + . (isset($element['#description']) ? '<span class="helper">' . $element['#description'] . '</span>' . PHP_EOL : '') + .'</label>' . PHP_EOL; + + return $output; } +/** + * Implements theme_checkboxes(). + */ +function unl_wdn_checkboxes($variables) { + $element = $variables['element']; + $attributes = array(); + if (isset($element['#id'])) { + $attributes['id'] = $element['#id']; + } + $attributes['class'][] = 'form-checkboxes'; + if (!empty($element['#attributes']['class'])) { + $attributes['class'] = array_merge($attributes['class'], $element['#attributes']['class']); + } + return '<ol ' . drupal_attributes($attributes) . '>' . (!empty($element['#children']) ? $element['#children'] : '') . '</ol>'; +} +/** + * Implements theme_radios(). + */ +function unl_wdn_radios($variables) { + $element = $variables['element']; + $attributes = array(); + if (isset($element['#id'])) { + $attributes['id'] = $element['#id']; + } + $attributes['class'] = 'form-radios'; + if (!empty($element['#attributes']['class'])) { + $attributes['class'] .= ' ' . implode(' ', $element['#attributes']['class']); + } + return '<ol ' . drupal_attributes($attributes) . '>' . (!empty($element['#children']) ? $element['#children'] : '') . '</ol>'; +} diff --git a/sites/all/themes/unl_wdn/includes/webform.inc b/sites/all/themes/unl_wdn/includes/webform.inc new file mode 100644 index 0000000000000000000000000000000000000000..3825c5f9f5f8f19f184ca059a30bd7592b1113da --- /dev/null +++ b/sites/all/themes/unl_wdn/includes/webform.inc @@ -0,0 +1,116 @@ +<?php + +/** + * @file + * Hooks to support UNL_WDN zenform styling and markup + */ + +/** + * Implements theme_webform_element(). + */ +function unl_wdn_webform_element($variables) { + // Ensure defaults. + $variables['element'] += array( + '#title_display' => 'before', + ); + + $element = $variables['element']; + + // All elements using this for display only are given the "display" type. + if (isset($element['#format']) && $element['#format'] == 'html') { + $type = 'display'; + } + else { + $type = (isset($element['#type']) && !in_array($element['#type'], array('markup', 'textfield'))) ? $element['#type'] : $element['#webform_component']['type']; + } + $parents = str_replace('_', '-', implode('--', array_slice($element['#parents'], 1))); + + $wrapper_classes = array( + 'form-item', + 'webform-component', + 'webform-component-' . $type, + ); + if (isset($element['#title_display']) && $element['#title_display'] == 'inline') { + $wrapper_classes[] = 'webform-container-inline'; + } + $output = '<li class="' . implode(' ', $wrapper_classes) . '" id="webform-component-' . $parents . '">' . "\n"; + $required = !empty($element['#required']) ? '<span class="form-required" title="' . t('This field is required.') . '">*</span>' : ''; + + // 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">' . _webform_filter_xss($element['#field_prefix']) . '</span> ' : ''; + $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . _webform_filter_xss($element['#field_suffix']) . '</span>' : ''; + + switch ($element['#title_display']) { + case 'inline': + 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 .= "</li>\n"; + + return $output; +} + +/** + * Implements theme_webform_date(). + */ +function unl_wdn_webform_date($variables) { + $element = $variables['element']; + + $element['year']['#attributes']['class'] = array('year'); + $element['month']['#attributes']['class'] = array('month'); + $element['day']['#attributes']['class'] = array('day'); + + // Add error classes to all items within the element. + if (form_get_error($element)) { + $element['year']['#attributes']['class'][] = 'error'; + $element['month']['#attributes']['class'][] = 'error'; + $element['day']['#attributes']['class'][] = 'error'; + } + + $class = array('webform-container-inline'); + + // Add the JavaScript calendar if available (provided by Date module package). + if (!empty($element['#datepicker'])) { + $class[] = 'webform-datepicker'; + $calendar_class = array('webform-calendar'); + if ($element['#start_date']) { + $calendar_class[] = 'webform-calendar-start-' . $element['#start_date']; + } + if ($element['#end_date']) { + $calendar_class[] = 'webform-calendar-end-' . $element['#end_date']; + } + $calendar_class[] ='webform-calendar-day-' . variable_get('date_first_day', 0); + + $calendar = theme('webform_calendar', array('component' => $element['#webform_component'], 'calendar_classes' => $calendar_class)); + } + + $output = ''; + $output .= '<ol class="' . implode(' ', $class) . '">'; + $output .= drupal_render_children($element); + $output .= isset($calendar) ? $calendar : ''; + $output .= '</ol>'; + + return $output; +} \ No newline at end of file diff --git a/sites/all/themes/unl_wdn/template.php b/sites/all/themes/unl_wdn/template.php index 9d584274431757078b1cace919f09fdef2207c6c..4949d181728fb7ace322e262024ec3813645e6bf 100644 --- a/sites/all/themes/unl_wdn/template.php +++ b/sites/all/themes/unl_wdn/template.php @@ -1,13 +1,11 @@ <?php /** - * Implements hook_css_alter(). + * zenform implementation */ -function unl_wdn_css_alter(&$css) { - // Turn off some styles from the system module. - // If some of this is later found desireable, add "stylesheets[all][] = css/unl_wdn.theme.css" to unl_wdn.info and copy these files to that locaiton with edits. - $path = drupal_get_path('module','system'); - unset($css[$path.'/system.theme.css']); +if (theme_get_setting('zen_forms')) { + require_once dirname(__FILE__) . '/includes/form.inc'; + require_once dirname(__FILE__) . '/includes/webform.inc'; } /** diff --git a/sites/all/themes/unl_wdn/webform-calendar.tpl.php b/sites/all/themes/unl_wdn/webform-calendar.tpl.php new file mode 100644 index 0000000000000000000000000000000000000000..62ae7c754e494f781e45ad7b331cbc127aeaadcd --- /dev/null +++ b/sites/all/themes/unl_wdn/webform-calendar.tpl.php @@ -0,0 +1,14 @@ +<?php + +/** + * @file + * Theme the button for the date component date popup. + */ +?> +<?php if (theme_get_setting('zen_forms')) { + print '<li>'; +} ?> +<input type="image" src="<?php print base_path() . drupal_get_path('module', 'webform') . '/images/calendar.png'; ?>" class="<?php print implode(' ', $calendar_classes); ?>" alt="<?php print t('Open popup calendar'); ?>" title="<?php print t('Open popup calendar'); ?>" /> +<?php if (theme_get_setting('zen_forms')) { + print '</li>'; +} ?> \ No newline at end of file