Remove fieldset on a date field Drupal 7

For some reason you want to display the date field without the fieldset wrapper, it’s not difficult but it may take you time to notice that the theme function called is in the date.theme file (date module) :

/**
 * Returns HTML for a start/end date combination on form.
 */
function theme_date_combo($variables) {
  $element = $variables['element'];
  $field = field_info_field($element['#field_name']);
  $instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
 
  // Group start/end items together in fieldset.
  $fieldset = array(
    '#title' => t($element['#title']) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
    '#value' => '',
    '#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '',
    '#attributes' => array(),
    '#children' => $element['#children'],
  );
  return theme('fieldset', array('element' => $fieldset));
}

So to override the funtion and change the render of the field put this code in the template.php file of your theme :

/**
 * Render date field without fieldset
 */
function MYTHEME_date_combo($variables) {
  return theme('form_element', $variables);
}

Nice coding!

Show drupal status messages in omega theme region

I had to include the render of the drupal status messages ($messages) in the “region–content.tpl.php” template.

$messages is not available in regions (its a page variable, not a region variable). For Omega it is also a zone variable,

by default it is available in “zone–content.tpl.php”, to make it available for regions i had to add $messages via hook_region_process :

/**
 * Implements hook_process_region().
 */
function mytheme_process_region(&$vars) {
  $theme = alpha_get_theme();
  if ($vars['elements']['#region'] == 'content') {
    $vars['messages'] = $theme->page['messages'];
  }  
}

Than create a “region–content.tpl.php” which will contain :

<div<?php print $attributes; ?>>
  <div<?php print $content_attributes; ?>>
    <?php if ($messages): ?>
      <div id="messages" class=""><?php print $messages; ?></div>
    <?php endif; ?>
    <a id="main-content"></a>
    <?php print render($title_prefix); ?>
    <?php if ($title): ?>
    <?php if ($title_hidden): ?><div class="element-invisible"><?php endif; ?>
    <h1 class="title" id="page-title"><?php print $title; ?></h1>
    <?php if ($title_hidden): ?></div><?php endif; ?>
    <?php endif; ?>
    <?php print render($title_suffix); ?>
    <?php if ($tabs && !empty($tabs['#primary'])): ?><div class="tabs clearfix"><?php print render($tabs); ?></div><?php endif; ?>
    <?php if ($action_links): ?><ul class="action-links"><?php print render($action_links); ?></ul><?php endif; ?>
    <?php print $content; ?>
    <?php if ($feed_icons): ?><div class="feed-icon clearfix"><?php print $feed_icons; ?></div><?php endif; ?>
  </div>
</div>

Hope this will be useful!

Add custom table to Views in Drupal 6

While trying to fix an issue with google geocoding, I wanted to use a separate table for a list of “annonces” (content type) and then wanted to display the content of that table with views module.

By default views don’t display a custom table content but it provides a hook to do this – hook_views_data().

I have included this hook in mymodulename.views.inc file, which I created in a subdirectory named ‘includes’ of my module directory.

Here is the code in mymodulename.views.inc file :

function mymodulename_views_data() {
  // The 'group' index will be used as a prefix in the UI for any of this
  // table's fields, sort criteria, etc.
  $data['example_table_name']['table']['group'] = t('Import annonces');
  // Define this as a base table. 
  $data['example_table_name']['table']['base'] = array(
    'field' => 'annonce_id',
    'title' => t('example_table_name table'),
    'help' => t("Table contains imported annonces"),
    'weight' => -10,
  );
  // This table creates an 'implicit' relationship to the node table, so that when 'Node'
  // is the base table, the fields are automatically available 
  $data['example_table_name']['table']['join'] = array(
    'node' => array(
      'annonce_id' => 'nid',
      'field' => 'nid',
     ),
  );
  // Now, explain all the fields in this table. For
  // each field, you can define what field, sort, argument, and/or filter
  // handlers it supports. This will determine where in the Views interface you
  // may use the field.
  // Node ID field.
  $data['example_table_name']['nid'] = array(
    'title' => t('Node content'),
    'relationship' => array(
      'base' => 'node',
      'field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Node id in this table that references a node.'),
    ),
  );
  // Explain numeric fields in the table
  $data['example_table_name']['annonce_id'] = array(
    'title' => t('Id annonce'),
    'help' => t('annonce id'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['example_table_name']['filename'] = array(
    'title' => t('File name'),
    'help' => t('File imported'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_string',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['example_table_name']['files_count'] = array(
    'title' => t('Files count'),
    'help' => t('Count of imported files'),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  return $data;
}

and then added this code to mymodule.module to get views to know this new table:

/**
 * Implementation of hook_views_api().
 * 
 */
function mymodulename_views_api() {
	return array(
			'api'  => 2.0,
			'path' => drupal_get_path('module', 'mymodulename') . '/includes',
	);
}

Hope this will be helpful!

Loading a custom theme for drupal 7

 

in order to change the default theme for drupal 7,

you have to implement hook_custom_theme in your own module :

/**
 *
 * Implement hook_custom_theme
 *
 */
function mymodule_custom_theme(){
  global $user;
  // charging bartik theme for webmaster
  if (in_array('webmaster', $user->roles)){
    return 'bartik';
  }
}

in this example i have loaded bartik theme for the ‘webmaster’ role.