You are here

function commons_origins_preprocess_form in Drupal Commons 7.3

Implements hook_preprocess_form().

Since Commons Origins overrides the default theme_form() function, we will need to perform some processing on attributes to make it work in a template.

File

themes/commons/commons_origins/template.php, line 637
Process theme data.

Code

function commons_origins_preprocess_form(&$variables, $hook) {

  // Bootstrap the with some of Drupal's default variables.
  template_preprocess($variables, $hook);
  $element =& $variables['element'];
  if (isset($element['#action'])) {
    $element['#attributes']['action'] = drupal_strip_dangerous_protocols($element['#action']);
  }
  element_set_attributes($element, array(
    'method',
    'id',
  ));
  if (empty($element['#attributes']['accept-charset'])) {
    $element['#attributes']['accept-charset'] = "UTF-8";
  }
  $variables['attributes_array'] = $element['#attributes'];

  // Roll the classes into the attributes.
  if (empty($variables['attributes_array']['class'])) {
    $variables['attributes_array']['class'] = $variables['classes_array'];
  }
  else {
    $variables['attributes_array']['class'] = array_merge($variables['attributes_array']['class'], $variables['classes_array']);
  }

  // Give the search form on the search page pod styling.
  if (isset($element['#search_page']) || isset($element['module']) && ($element['module']['#value'] == 'search_facetapi' || $element['module']['#value'] == 'user')) {
    $variables['attributes_array']['class'][] = 'search-form-page';
    $variables['attributes_array']['class'][] = 'commons-pod';
    $variables['attributes_array']['class'][] = 'clearfix';
  }

  // Wrap some forms in the commons pod styling.
  $pods = array(
    'user-login',
    'user-pass',
    'user-register-form',
  );
  if (in_array($element['#id'], $pods)) {
    $variables['attributes_array']['class'][] = 'commons-pod';
  }

  // Give the dynamic filters a special class to target.
  if (strpos($element['#id'], 'views-exposed-form-commons-homepage-content') === 0 || strpos($element['#id'], 'views-exposed-form-commons-events-upcoming') === 0 || strpos($element['#id'], 'views-exposed-form-commons-bw') === 0) {
    $variables['attributes_array']['class'][] = 'dynamic-filter-lists';
  }

  // Give the keyword filter a pod wrapper.
  if (strpos($element['#id'], 'views-exposed-form-commons-groups') === 0) {
    $variables['attributes_array']['class'][] = 'keyword-filter';
    $variables['attributes_array']['class'][] = 'commons-pod';
  }

  // Set an identifying class to the event attendance form.
  if (strpos($element['#id'], 'commons-events-attend-event-form') === 0) {
    $variables['attributes_array']['class'][] = 'node-actions';
  }

  // Make sure the bottom of the partial node form clears all content.
  if (strpos($element['#form_id'], 'commons_bw_partial_node_form_') === 0) {
    $variables['attributes_array']['class'][] = 'user-picture-available';
    $variables['attributes_array']['class'][] = 'clearfix';
  }

  // Place the user avatar to the left of the private message form content.
  if ($variables['element']['#form_id'] == 'commons_trusted_contacts_messages_popup') {
    $variables['content_attributes_array']['class'][] = 'user-picture-available';
  }
}