# Question
Title: Can't filter Calendar according to event date instead of date added
Hi I'm trying to figure out this issue as well. i have calendar that only shows the dates the event has been posted, not the actual start date for which I created the field. I can't seem to filter dates according to their start day. When I try to filter it, it's not giving me the date field option. :( Can someone direct me toward good tutorial or help me set it up. Thank you in advance.

# Answer
You need to set up the Date argument. See Drupal therapy's video tutorial on this http://www.drupaltherapy.com/date. Also here's an output a properly configure calendar view

```
$view = new view;
$view->name = 'calendar';
$view->description = 'A multi-dimensional calendar view with back/next navigation.';
$view->tag = 'Calendar';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'value',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'sticky' => array(
    'order' => 'DESC',
    'id' => 'sticky',
    'table' => 'node',
    'field' => 'sticky',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'field_date_value' => array(
    'order' => 'ASC',
    'delta' => '-1',
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'date_argument' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'date',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'date_fields' => array(
      'node_data_field_date.field_date_value' => 'node_data_field_date.field_date_value',
    ),
    'year_range' => '-1:+1',
    'date_method' => 'OR',
    'granularity' => 'month',
    'id' => 'date_argument',
    'table' => 'node',
    'field' => 'date_argument',
    'relationship' => 'none',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'product' => 0,
      'event' => 0,
      'audio' => 0,
      'blog' => 0,
      'gallery' => 0,
      'gallery_image' => 0,
      'page' => 0,
      'simplenews' => 0,
      'story' => 0,
      'video' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Override',
    ),
    'default_options_div_prefix' => '',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
    ),
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'event_product' => 'event_product',
      'event' => 'event',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Calendar');
$handler->override_option('header_empty', 1);
$handler->override_option('items_per_page', 0);
$handler->override_option('use_more', 0);
$handler->override_option('style_plugin', 'calendar_nav');
$handler = $view->new_display('calendar', 'Calendar page', 'calendar_1');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '([field_date_value])',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
));
$handler->override_option('path', 'calendar');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('calendar_colors', array(
  '0' => array(),
));
$handler->override_option('calendar_colors_vocabulary', array());
$handler->override_option('calendar_colors_taxonomy', array());
$handler->override_option('calendar_colors_group', array());
$handler->override_option('calendar_popup', 0);
$handler->override_option('calendar_date_link', '');
$handler = $view->new_display('calendar_block', 'Calendar block', 'calendar_block_1');
$handler->override_option('block_description', 'Calendar');
$handler->override_option('block_caching', -1);
$handler = $view->new_display('calendar_period', 'Year view', 'calendar_period_1');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'display_type' => 'year',
  'name_size' => 1,
  'max_items' => 0,
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'year');
$handler = $view->new_display('calendar_period', 'Month view', 'calendar_period_2');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '([field_date_value])',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
));
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'name_size' => '2',
  'with_weekno' => '0',
  'max_items' => '0',
  'max_items_behavior' => 'more',
  'groupby_times' => 'hour',
  'groupby_times_custom' => '',
  'groupby_field' => '',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'month');
$handler = $view->new_display('calendar_period', 'Day view', 'calendar_period_3');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'name_size' => '99',
  'with_weekno' => 0,
  'max_items' => 0,
  'max_items_behavior' => 'more',
  'groupby_times' => 'hour',
  'groupby_times_custom' => '',
  'groupby_field' => '',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'day');
$handler = $view->new_display('calendar_period', 'Week view', 'calendar_period_4');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'name_size' => '99',
  'with_weekno' => 0,
  'max_items' => 0,
  'max_items_behavior' => 'more',
  'groupby_times' => 'hour',
  'groupby_times_custom' => '',
  'groupby_field' => '',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'week');
$handler = $view->new_display('calendar_period', 'Block view', 'calendar_period_5');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'display_type' => 'month',
  'name_size' => '1',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 0,
  'default' => 0,
  'calendar_block_1' => 'calendar_block_1',
));
$handler->override_option('calendar_type', 'month');
$handler = $view->new_display('block', 'Upcoming', 'block_1');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value_1' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 1,
    'id' => 'field_date_value_1',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '[field_date_value] <br />([field_date_value_1])',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'date_no_time',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
  'field_teaser_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 1,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_teaser_value',
    'table' => 'node_data_field_teaser',
    'field' => 'field_teaser_value',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array());
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'date_filter' => array(
    'operator' => '>=',
    'value' => array(
      'min' => NULL,
      'max' => NULL,
      'value' => NULL,
      'default_date' => 'now',
      'default_to_date' => '',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'date_fields' => array(
      'node_data_field_date.field_date_value' => 'node_data_field_date.field_date_value',
    ),
    'date_method' => 'OR',
    'granularity' => 'day',
    'form_type' => 'date_select',
    'default_date' => 'now',
    'default_to_date' => '',
    'year_range' => '-1:+1',
    'id' => 'date_filter',
    'table' => 'node',
    'field' => 'date_filter',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('title', 'Upcoming Events');
$handler->override_option('items_per_page', 4);
$handler->override_option('use_more', 1);
$handler->override_option('use_more_always', 1);
$handler->override_option('use_more_text', 'view calendar');
$handler->override_option('style_plugin', 'default');
$handler->override_option('style_options', array(
  'grouping' => '',
));
$handler->override_option('block_description', 'Upcoming');
$handler->override_option('block_caching', -1);

```
> 2 votes

# Answer
In D6 and Views 2 (not positive about D7), you need to change the Date argument in Views. If using the default Calendar to start, click on `Date: Date (node)`, scroll down to **Date field(s)** and mark the checkbox of the field you wish to use. Then to filter the events, add a new filter and find `Content: YOUR DATE FIELD` and set the filter settings.

Not knowing what version of Drupal you are using, here are some resources that might also be useful to you to get started:

D7 Calendar installation & configuration (Screencast)
D6 Calendar installation & configuration (Screencast)
How to create an Upcoming Events list (Screencast)
Date/Calendar Documentation
> 2 votes

---
Tags: datetime
---


title: How to handle URLs like node/%.atom?

text:
# Question
Title: How to handle URLs like node/%.atom?
I am writing a module to generate a custom Atom feed, and I want to create URLs like http://drupalsite/node/20.atom or http://drupalsite/content/nodealias.atom.

I was trying to implement it as follows, but of course it is not correct.

```
$items['node/%.atom'] = array(
        'title' => 'atom node feed',
        'page callback' => 'atom_node_feed',
        'page arguments' => array(1),
        'access callback' => 'user_access',
        'access arguments' => array('generate atom feed'),
        'type' => MENU_CALLBACK
    );

```

Is it at all possible to create URLs like this in Drupal?

# Answer
Another user asked a very similar question on S.O. earlier: How to add .html extensions in Drupal project

You could try using the Pathauto module to create aliases for your URLs, simply adding on the `.atom` at the end. More on Pathauto:

> The Pathauto module automatically generates path aliases for various kinds of content (nodes, categories, users) without requiring the user to manually specify the path alias. This allows you to get aliases like `/category/my-node-title.html` instead of `/node/123`. The aliases are based upon a "pattern" system which the administrator can control.
>
> Pathauto depends on the Token module. See screenshots of the bulk delete and the admin settings screen. View a screencast of Using Pathauto and Views to get Index Aliases.
> 2 votes

# Answer
The code you wrote doesn't work because you are using a placeholder in the definition of the menu callback; such placeholders can be of two types:

* anonymous placeholder. The placeholder is just *%*, which matches any string.
* named placeholder. In this case, the placeholder is similar to *%node*, *%user*, used from Drupal core modules. If the placeholder is, for example, *%node*, Drupal will look for the `node_load()` function, and will pass it the string that in the path replaces the placeholder; when the function returns `FALSE`, then Drupal will return a 404 error page to the user. As the string following the *%* is used as name of the load function, to which the string "\_load" is appended, characters that are not allowed in a function name are discarded (PHP cannot have a function with a name like `.atom_load()`.

If your purpose is to define a menu callback for your module that returns an atom feed for the node, then I would define the callback as the following:

```
$items['node/%node/atom'] = array(
  'title' => 'atom node feed',
  'page callback' => 'atom_node_feed',
  'page arguments' => array(1),
  'access callback' => 'user_access',
  'access arguments' => array('generate atom feed'),
  'type' => MENU_CALLBACK,
);

```

The page callback will get the node object as first argument, not the node ID.

To create a path like http://drupalsite/node/20.atom, you need to create a path alias. You can assign path aliases using the administrative page at admin/config/search/path (Drupal 7) or admin/build/path (Drupal 6).
Using Drupal 7, a module can create a path alias calling path\_save().
You can also use Pathauto to automatically set path aliases for nodes. The module uses tokens that allows to dynamically create path aliases that follows a defined schema. As far as I know, node path aliases are just set for paths like node/1; the path alias is not set for a path like node/1/edit, or node/1/atom.
> 6 votes

---
Tags: routes
---


# Question
Title: Send notification e-mail after new content was added
Some people refuse to learn about RSS and wish they could give me (e.g., via some form) e-mail (without registration) and they would be automatically notified about new content.

Could you help me how to achieve this functionality in Drupal 7? I heard about three modules that could help : Rules, Subscriptions and Notify. Only the first works under Drupal 7. Could you configure this functionality with some suitable module?

# Answer
> 19 votes
Rules is best for this, it depends on Entity API.

* Simple download and enable them from Admin -\> Modules
* Now follow Admin -\> Configuration -\> Workflow -\> Rules
* Click on `Add new rule`
* Define name e.g. `"New content email notification"` , select `'After Saving new content'` from React on event select box and hit the Save
* On the next page, event is already defined, No condition is required to define here, Head on to Action section and hit `Add action`
* Enter recipient email address in the `To` field box
* Populate Subject and Message, From fields. (A number of Replacement pattern are available to include in the text)

e.g. New content \[node:title\] added by \[node:author\] of type \[node:type\] on \[node:created\].

* Hit the save
* On the settings fieldset, make sure to check `Active` check box.

# Answer
> 7 votes
...alternatively, if you need to do this programmatically (not via Rules module), you can hook into hook\_node\_insert() and grab the $node object, then do with it what you want.

# Answer
> 2 votes
Rules will do exactly this:

> Example use cases
> \- Build flexible content publishing workflows changes
> \- Send customized mails to notify your users about important
> \- Create custom redirections, system messages, breadcrumbs, ...

Do you need help configuring it ?

---
Tags: 7, notifications
---


# Question
Title: Simple Panels question on where the panels get placed on the page
This is a silly question but how does Panels know where to insert the panels I just made? I didn't type a single line of PHP and yet there it is! It's like magic (woooh...)! On a side note, can I define where it gets placed through PHP? Thanks.

# Answer
Panels places the panel into the 'content' region of the selected page.

If you want to place it somewhere else on the page, try using mini-panels to create a block and place it that way. No need to write custom PHP code for that.
> 1 votes

---
Tags: 7, panels
---


title: Override the taxonomy pages

text:
# Question
Title: Override the taxonomy pages
In Drupal 7, you can use **taxonomy-term.tpl.php** to override taxonomy pages.

Inside the taxonomy-term.tpl.php page, you can use `<?php print $term->field_NAME['und'][0]['value'];?>`to print out the content of any fields attached to the taxonomy term. (\*)

However, how do you get to the list of nodes that is displayed on the taxonomy page?

There doesn't seem to be anything in the taxonomy-term.tpl.php file to indicate how to theme the nodes that are displayed on the term page.

I know you can use Views to over ride the page. However, Views does not let you display nodes tagged with a term and fields that are attached to the term in a single View.

(\*) I know you are not supposed to use UND. However, the correct method for access node based fields does not seem to work with taxonomy based fields.

# Answer
> 2 votes
The template file you want to use is not taxonomy-term.tpl.php; that's used for the taxonomy header at the top of the page. The template file used is node.tpl.php.

If you look at taxonomy\_term\_page() which is used to build the term page view, you will see the nodes are build separately by calling node\_view\_multiple(). `node_view_multiple()` is just a wrapper for node\_view(), which uses the standard node.tpl.php file.

Also you should be able to use `field_get_items()` for taxonomy terms. I'll look for something like `$field = field_get_items('taxonomy_term', $term, 'field_name');`.

I haven't tried but it should work.

You should really never use `'und'`, but the constant LANGUAGE\_NONE.

---
Tags: taxonomy-terms, theming
---


# Question
Title: How to make the UserProfile Info availlable on a block
I understand how to preprocess a specific block to make some variable available for that it, but what I don't understand is where I grab these variable that I want to be available in my block.

I have the following code:

```
function THEME_preprocess_block(&$variables) {
    $variables['user_profile']= $user_profile;
}

```

`$user_profile` is `NULL`.

So in other terms what i would like is to grab all the data entered by a user during the registration and make it available within block under for instance a user\_profile variable. Is it possible at all?

---

Well i tried but it doesn't seem to do anything in drupal 7. Also isn't the user variable holding data only for the current loged in user ? I would like to retrieve the data of any user in order to populate the profile page with it.

# Answer
Here is the correct snipet:

```
function THEME_preprocess_block(&$variables) {
    $variables['user_profile'] = menu_get_object('user');
}

```
> 0 votes

# Answer
You need to use the global user object to get info about the currently logged in user, then pass that user object to profile\_load\_profile:

```
function THEME_preprocess_block(&$variables) {
    global $user;
    $user_profile = profile_load_profile($user);
    $variables['user_profile']= $user_profile;
}

```

(code is untested but should work)
> 2 votes

---
Tags: users
---


title: Organic Groups for grouping users?

text:
# Question
Title: Organic Groups for grouping users?
I have a project where I want to group users. So for example, say we have a role of 'King' and a role of 'Subject'. I will have a view where a King can see a listing of all of their subjects. When a new user registers, they will sign up under the name of a King, so they will self-organize as to who they are a subject of.

Is Organic Groups an appropriate module for this functionality? I've watched a few tutorials, and it seems to be about sharing (or actually hiding and providing special access to) content. Here I'm not really so concerned about content, but rather grouping users.

If not Organic Groups, is there a good module for grouping users? This is for Drupal 7.

# Answer
> 1 votes
As far as I know, organic groups would work great for this. You can easily just hide links to the group frontpages.

---
Tags: 7, organic-groups
---


title: Integrating Authorize.net into Drupal

text:
# Question
Title: Integrating Authorize.net into Drupal
I have a friend with a single page website that sells a single product. All he wants is an order form embedded on the one page that uses authorize.net. I can't find a single way to embed the form onto the website like I can embed a mailchimp form, for example. Do I need to set up an Advanced Integration Method to accomplish this? If I need to would it be easiest to do it though Drupal? And, what is the easiest way to do it through Drupal?

# Answer
> 2 votes
hook\_menu

```
items['authorize-form'] = array(

  'title' => t('Pay via Authorize'),

  'page callback' => 'generate_authorize_form',

  'access arguments' => array('access content'),

  'type' => MENU_CALLBACK

);

```

Callback function to generate authorize form using Authorize.net SDK

```
function generate_authorize_form(){
    require_once 'anet_php_sdk/AuthorizeNet.php'; // The SDK
    $url = "http://YOUR_DOMAIN.com/index.php";
    $api_login_id = 'xxxxxxxxx';
    $transaction_key = 'xxxxxxxxxxxxxxxx';
    $md5_setting = 'xxxxxxxxx'; // Your MD5 Setting
    $amount = "5.99";

    ob_start();
    AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting);

    $output = ob_get_content();
    ob_end_clean();
    return $output;
}

```

---
Tags: payment-gateways
---


# Question
Title: How To Redirect to a Named Node upon Registration
Given a D6 site where users must confirm their email address, I would like new registrants to be immediately redirected to a Page node which explains the email verification process.

I attempted to do this using Actions and Triggers, but "Trigger: After a user account has been created" executes before the activation email is sent and so the message is blocked and never gets out. This appears to be an unresolved issue tracing as far back as D5.

The Login Destination module is listed as supporting this feature for D7.x but not 6.x.

# Answer
You can use the Rules Module to redirect a user after an account is created.

* Simply add a new rule for the event "User account has been created"
* Add an action of "Page redirect"
* Fill in the information for the page you want to redirect the user to.

Make sure that "Immediately issue the page redirect" is **not** checked or else the same thing will happen and the email will not get sent.
> 5 votes

# Answer
Another good solution would be to use LoginToboggan
> 0 votes

---
Tags: 6, users, redirection
---


# Question
Title: Notice: Trying to get property of non-object
Here is my code:

```
function THEME_preprocess_block(&$variables) {
    $variables['user_profile'] = menu_get_object('user');
}

```

I print the field "name" using `print $user_profile->name`, and I get the following error:

> Notice: Trying to get property of non-object in include() (line 71 of SITE\sites\all\themes\parce\block--block--2.tpl.php).

I assumed `$user_profile` was not an object and I tried `print render($user_profile['name'])`, which returned me:

> Fatal error: Cannot use object of type stdClass

What is going on? I checked the Drupal API reference, and `menu_get_object()` should return me an object.

# Answer
You didn't print line numbers of the second error so I don't know if they happen on then same line. Maybe your notice is from something else.

What you could try is to print out the variable using `print_r`, `vardump`, `debug` or use the Devel module which creates some wrapper functions like `dpm` to print variables with Krumo.

It should be impossible that the same variable is an object and isn't an object at the same time. But it's hard to say more with the info you provided.

**Update:**
From your comments, I can see why you are getting the errors:

```
print $user_profile->field_country['und']['0']['value'];

```

Error \>\> Notice: Undefined index: **und** ...

```
print $user_profile['field_country']['und']['0']['value'];

```

Fatal \>\> Cannot use object of type stdClass as array

The problem as I marked in the error message is that `und` is not defined in the field value. So `$user_profile->field_country` is ok but `$user_profile->field_country['und']` is undefined. The reason could be that it doesn't have a value set or that the language for the field isn't undefined. You should like I suggested above, print out the variable to see what it contains.
> 4 votes

# Answer
`menu_get_object('user')` returns you an object only for specific URLs; if the URL of page where the block is visible is http://example.com/node/1, then the function will not return you an object.

As reported in the documentation:

> `menu_get_object()` provides access to objects loaded by the current router item. For example, on the page node/%node, the router loads the %node object, and calling `menu_get_object()` will return that.

In your case, the page URL should match user/%user, such as in the case of http://example.com/user/1, http://example.com/user/1/shortcuts, http://example.com/user/1/devel.

The function could also not return an object when the block is being shown in a user profile page, and if there are problems loading the user object. In this case, the user profile page would not be correctly visualized too, I guess.
> 0 votes

---
Tags: users
---


# Question
Title: Looking for a function that searches for nodes
Is there a function in Drupal-7 that looks or searches for nodes that match some criteria (e.g. promoted nodes, published nodes, nodes of a specific content type), rather than using Views?

# Answer
The closest thing that you get is EntityFieldQuery, which will allow you to construct a query that will yield the nodes that match the conditions.
> 4 votes

---
Tags: nodes
---


# Question
Title: What is the difference between page callback and access callback?
Can anyone please explain with example for difference between page callback and access callback in drupal?

# Answer
> 7 votes
* page\_callback is a function called which will be used to generate contents of the page
* access\_callback is a function called which will be used determine if a user has access to view the page. This can be used where a simple permission isn't enough. An example would be that the author of the node would be allowed to edit the node or any user with a special admin permission.
Note the access\_callback will by default be the `user_access` function which will check that the user has a specific permission.

Both of these keys have a sidekick, `[page/access] arguments` which should be an array of arguments that is passed to the function. arguments can either be static or you can use numbers to reference the URL. If a load function us used on a URL arg, like `%user`, referencing it will yield the return of the load function, like the user object instead of the user id (uid).

Page callbacks will receive any URL args that aren't used for pattern matching. So if you define an URL `foo/bar` and user goes to `foo/bar/baz`, `baz` will be added to the list of args passed to the page callback. This can be handy in some cases where you can provide a default argument that can be overridden in the URL.

If in doubt always check the api refference api.drupal.org

# Answer
> 2 votes
Page callback: a function that is responsible to provide html for the page e.g.

```
function get_html(){
    return "<html>";
}

```

or drupal\_get\_form() if page is generation a form. In this case 'page arguments' are required to link form defining callback with it.

Access callback: A function that is responsible to check a user has access on the content of this page callback.

normally it is user\_access()

---
Tags: routes
---


# Question
Title: how to show a link only on my own profile node?
tried this code:

```
<?php
global $user;
if (arg(0) == 'user' && $user->uid == arg(1)){
$url = privatemsg_get_link(array(user_load($node->uid)));
print '<div class="pm">'. l(t('Send a private message to the author'), $url, array('attributes' => array('class' => 'lichnoe'))) .'</div>';
}
?>

```

but this doesn't works. It displays on my own profile, but doesn't displays on other user's profile. What i'm doing wrong?

# Answer
The code you have posted above will check if you are on the `user/[uid]` page for the user that is logged in. So it will take effect for the user's own user page. If you wanted to post the link on all pages except the user's own page you should instead do

```
if (arg(0) == 'user' && is_numeric(arg(1)) && $user->uid != arg(1)) {

```
> 1 votes

---
Tags: privatemsg
---


# Question
Title: Secondary submit function for form input button
I want to have buttons for remove selected field from form.

```
    $form['questions']['buttons'][$counter] = array(
        '#type' => 'button',
        '#name' =>'button_'.$counter,
        '#value' => t('Remove'),
        '#submit' => array('my_mod_remove_submit'),
    );

```

Submit function:

```
function my_mod_remove_submit($form, &$form_state) {
    drupal_set_message('<pre>'.print_r($form_state, 1).'</pre>');
}

```

But it seems that this function is never invoke.

# Answer
The problem with your code is the default value for the form field attributes. In the case of the "button" form field, these are the default values:

* `#name` =\> 'op'
* `#button_type` =\> 'submit'
* `#executes_submit_callback` =\> FALSE
* `#ahah['event']` =\> 'mousedown'

Those are also the default values for Drupal 7.

If you want to use a submission callback for a button, then you need to change the form field definition to the following one:

```
$form['questions']['buttons'][$counter] = array(
  '#type' => 'button',
  '#name' =>'button_' . $counter,
  '#value' => t('Remove'),
  '#executes_submit_callback' => TRUE,
  '#submit' => array('my_mod_remove_submit'),
);

```

As alternative, instead of using a "button" form field, you should use a "submit" form field.
> 4 votes

# Answer
Change the input type from "button" to "submit"
> 1 votes

# Answer
I think you want to manage multiple submit buttons associated with their data to perform operations on it.

The better approach is to use check boxes with a single submit button.

e.g.

```
function my_form(){
  $data_ids = array();

  foreach($data_set as $data){
    $data_ids[$data] = '';
    $form['data']['data_preview'][$data['id']] = array('#value' => $data['value']);
  }

  $form['selection'] = array(
    '#type' => 'checkboxes'
    '#options' => $data_ids;
  );

  $form['process'] = array(
    '#type' => 'submit',
    '#value' => 'do',
  );

  $form['#theme'] = 'my_form';
}

```

Theme handler (do not forget to implement `my_form` entry in `hook_theme`)

```
function theme_my_form($form = array()){
  $rows = array();
  foreach(element_children($form['selection']) as $id) {
    $fields = array();
    $fields[] = drupal_render($form['selection'][$id]);
    $fields[] = drupal_render($form['data']['data_preview'][$id]);
    $rows[] = $fields;
  }

  $output = theme('table', array('Select', 'Data'), $rows);
  $output .= drupal_render($form);// Render rest of form
  return $output;
}

```

Now form submit handler

```
function my_form_submit(&$form, $form_state){
  $clicked_button = $form_state['clicked_button']['#value'];
  $values = $form_state['values'];

  if ($clicked_button == $values['process']){
       //Here check $value['selection'] array and process accordingly
  }
}

```
> 0 votes

---
Tags: 6, forms
---


# Question
Title: Is it safe to connect to another server to send form data?
I have a standard D7 installation and I was wondering if it's safe to **connect to another server** to send form data. The way I see it, I'll need to make a `page--<path>.tpl.php` file and add my PHP at the very top of it. Are there any issues I should know about before doing this? Is this ok to do?

The form is for Anonymous users so no registration is required, it's just that the data needs to be sent elsewhere (another server). Yes, I've tried the Webform module but it's just not what I'm looking for. I'm thinking of using **AJAX** to send the data.

Any tips/suggestions before I go about this or should I just wing it? :-)

# Answer
> 1 votes
If you clear your required flow then a better solution can be suggested.

It is not a good practice to perform at `page--path.tpl.php`

Use `hook_init` in your custom module and check arg(1) to confirm your path.

Data can also be posted using `drupal_http_request($server_url, $headers, 'POST', $data);`

---
Tags: 7, ajax
---


title: How is Drupal Planet realised?

text:
# Question
Title: How is Drupal Planet realised?
How is the Drupal Planet realised? I found the Planet installation profile, but it seems to be dead (the Git instructions tab is empty).

# Answer
> 2 votes
Drupal planet is built upon the core aggregator module, blogs are required to set up a special feed (generally tagging it drupal-planet) to be imported in the list.

That should be pretty simple to reproduce: What is Planet Drupal and how do I get added?

---
Tags: feeds
---


# Question
Title: Google rich snippets, custom content type
I use Drupal 7.

I have a custom content type which, among other fields, uses Fivestar ratings.

I would like to have my node content enriched with microdata/microformarts/rdf so that it appears in Google Rich Snippets.

I tried RDF module, but it cannot apply detailed formating at the Fivestar module results, because Fivestar produces rating and number of reviews as one field.

I would like to recreate node.tpl.php, by printing field by field and not just `$content`. Also I would like to find out how to break down the fivestar two number results down to each compenents, so that I can put the right microdata in the markup.

More information about rich snippets is at http://www.google.com/support/webmasters/bin/answer.py?answer=99170.

How I can find out the variables and arrays that are used to print the content of a node?

How can I print one by one at node.tpl.php, so that I am able to put the right rich snippets markup in between?

edit: ok, till now I have found about devel module and that I must use dpm($content) inside my node--type.tpl.php. I manage to print render($field\_names) of various other fields, but I could not yet understand yet about fivestar module values.

# Answer
> 1 votes
This can be accomplished by printing the values you're self instead of letting fivestar do the default rendering.

Here's an example:

```
$results = fivestar_get_votes('node', $node->nid, 'tag');
//$results now has everything you need to do microformats

```

The results will have the average and counts. You can print those variables where ever you like. Also note you probably should disabling the text display on the fivestar widget.

There is also an issue over at http://drupal.org/node/901260.

---
Tags: theming
---


# Question
Title: Voting API + Fivestar Voting - Restricting votes to user and not to IP
I want Fivestar rating to be restricted to the logged in user and NOT to the IP they are using.

I want two (or more) logged in users using the same IP being able to have their own votings. At the moment it is possible to influence each other votings.

Am I missing something?

# Answer
> 2 votes
This is the default behavior.

Votingapi will limit to IP address when a user is anonymous. If the user is logged in the voting will be restricted by the User ID not ip address.

What version of votingapi are you using? If you're having a problem where this isn't the behavior a bug report might be more helpful.

# Answer
> 0 votes
Nope, unfortunately (AFAIK) this is a limitation of Voting API.

When faced with the same problem in the past I ended up resorting to hacking the module and adding that functionality. (it was a while ago though, maybe something changed?)

---
Tags: rating
---


# Question
Title: Extract all images out from each node in content type
Every time a new node is published within a single content type, I wish to extract (not remove) all the images out from that node's body and save the URL(s) of the images in the database. I will then use the URLs to make a slideshow of the images on a separate node.

I have three questions:

1. Which hook runs right before a node is published?
2. What's the best way of saving those URLs in the database?
3. Which Drupal function do I use to retrieve those URLs from the database?

# Answer
> 1 votes
> Which book runs right before a node is published?

* hook\_node\_update($node) The hook is invoked after the node is inserted/updated in the node table

> What's the best way of saving those URLs in the database?

* It totally depends upon your needs, Simply you will have to save in database in your own table(s).

> Which Drupal function do I use to retrieve those URLs?

---
Tags: 7, media
---


title: Views Arguments Title

text:
# Question
Title: Views Arguments Title
I have a view which has an argument passed to it. I provide a default argument of "User ID from URL". I then use `%1's content` in the Title. This returns `username's content`.

I have a content profile associated with a user. I want to get the `field_first_name` from the content profile and display it in the title. So I would get `Lucy's content`. How can this be achieved?

# Answer
> 2 votes
Edit your argument for configuration Add validator options for your argument by selecting PHP Code from the select box Add following code in it

```
 $usr = user_load(array(uid => (int)arg(2))) //Check the appropriate position of uid
 $view->display['page_2']->handler->handlers['argument']['date_argument']->options['title'] = $usr->field_first_name . "'s content";

```

Here `page_2` is views identifier and `date_argument` is argument identifier.

---
Tags: views, 6
---


# Question
Title: How to display a profile form using profile2 module
Profile2 is a module that uses entities to create profiles that are separate from the user account.

From within my module, I want to be able to display a form to edit the profile entities. Possibly using drupal\_get\_form or maybe Profile2's API or any other method.

What is the best way to go about this?

# Answer
> 20 votes
I did something like this recently. Since profile uses fields, this make things pretty simple. For the form you could do something like this:

```
function my_profile_form($form, &$form_state) {
  global $user;
  if (!isset($form_state['profiles'])) {
    $profile = profile2_load_by_user($user, 'profile_machine_name');
    if (!$profile) {
      $profile = profile_create(array(
        'type' => 'profile_machine_name',
        'uid' => $user->uid
      ));
    }
    $form_state['profiles'][$profile->type] = $profile;
  }

  // Use field attach form and handle the fields yourself:
  field_attach_form('profile2', $profile, $form, $form_state);
  // Or use profile2 API which is simpler
  profile2_attach_form($form, $form_state);

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}

```

Since all the profile form only is the fields that are attached to the profile, you can simply attach the fields yourself to the form, using Drupal core APIs:

* `field_attach_form` adds the fields to the form.
* `field_attach_validate` handles validation.
* `field_attach_submit` to handles adding the values to the entity (profile).
* Lastly you would need to save the profile entity using `profile2_save`.

After browsing the profile2 module code, I found that it provides a wrapper function to attach the fields to the form and save the form. This is simpler, but in doing so, you loose a little control. To use this you need to use the `profile2_attach_form`. Doing this will also handle the validation and saving of data.

To use the above code you should be able to c/p it, rename the form and replace `profile_machine_name` with the actual machine name of the profile you want to display the form for.

---
Tags: 7, users
---


# Question
Title: Why does drupal_set_message not appear in the message area?
I often use something like `drupal_set_message( krumo( $row ) );` to output debug information. This is suppose to output that message within the $message area placed via the page.tpl file, however sometimes this is output in line where the code is suppose to be rendering (via a field template.)

Is there any way to make drupal\_set\_message output to the right place when being used in the the theme layer?

# Answer
Whenever you call `drupal_set_message()`, or a function that outputs to the message area in a template it will not show until the next page refresh.
This is due to the fact that when the template files are being rendered, the messages to be displayed have already been pulled and rendered themselves. A refresh of the page in question after the first rendering should show the output of `dpm()` or what you have; just keep in mind it was for the page called before.
> 2 votes

# Answer
You do not have to call krumo directly. You can just use the helper function dpm, this will print a krumo output on the message variable.

Example:

```
dpm($row);

```
> 4 votes

# Answer
You can use `drupal_get_messages` to get the messages that have been set. But calls to `drupal_set_message` that happens after/during the page is rendered is hard to include.

You would need to theme the messages as well before adding them to the page.
> 3 votes

---
Tags: theming
---


# Question
Title: Displaying a block on a content profile page passing the content profile nid into the block
I have a view block. It takes an argument to filter the content. The argument is the nid of a content profile. I then use a relationship to get the uid of the content profile. This uid means I only returns nodes related to the user of the content profile.

I wish to display this block on the users content profile page. So there would be a block listing nodes from the same user on there content profile. I am displaying the block using context.

What is the best way to get the filtering to occur. I currently am passing an argument which gets the nid of the content profile from the url. I have been told that I can do this by using spaces and contexts and not my custom php. How would you do this\>

# Answer
> 1 votes
Add an argument of type Node\[nid\] to your views

Configure `Action to take if argument is not present` for `Provide default argument` as `PHP Code`

Add following code in the text area

```
  $node = node_load((int)arg(1));
  return $node->uid;

```

---
Tags: views, 6, blocks
---


title: Taxonomy sorting in view

text:
# Question
Title: Taxonomy sorting in view
I am a Drupal newbie using Drupal 7.

I made a taxonomy for documents, and then a view in the views module to list the documents. When the view searches by the taxonomy term, it seems to sort by the term's ID number, rather than the name of the term. I want an alpha sort on the term, not the ID number. Is there a setting to change this that I've missed, or do I need to do programming to change it? Seems like a pretty common situation.

ID Name
1 Homeland Security
2 Criminal Justice
3 Violence Against Women

will sort as above, not with Criminal Justice first.

# Answer
Make sure you have `Taxonomy: Term` selected under the Sort Criteria box and not `Taxonomy: Term ID`.

I believe the sort that you are seeing under Format -\> Settings is where you can select which fields are sortable and the default sort for a view of format: Table. Making a field sortable creates a clickable link as a header for the table column allowing you to change the sort order by that field.
> 1 votes

# Answer
* Create a view and select type as `Term`
* Add field `Taxonomy Term`
* Add sort criteria `Taxonomy Term` and then define sort order
> 0 votes

---
Tags: views, taxonomy-terms
---


# Question
Title: CCK form to edit single field or set of fields
We have a fairly large CCK content type and would like to be able to edit a single field of the node at a time (or a set of fields).

For example, we will display our content on the page through a custom view, with a series of "edit" icons per row, allowing the user to edit an individual fields values.

Ideally we are aiming to have a popup with that fields form item(s), which the user can edit and click update.

Manipulating the form after build is not practical as its so much overhead just to render a form with a single field.

Is there a module that can render a form for one or a series of the fields for the given node?

# Answer
> 1 votes
Is it for D6, if so this module will solve your problem: jEditable inline content editing.

# Answer
> 1 votes
I would go with Views and the Editable fields module

---
Tags: entities
---


title: cache_clear_all() doesn't seem to work

text:
# Question
Title: cache_clear_all() doesn't seem to work
I have a block with a few CCK fields. In this block I have a link to an action that changes the value of the fields in that block.

The code is the following:

```
db_query("UPDATE {content_type_event} SET field_event_places_amount_value = field_event_places_amount_value - 1 WHERE nid=%d", $nid);
cache_clear_all();

```

After reloading, the old value still appear. I have to manually clear the cache to see the current value.

# Answer
Since it's a CCK field I need to use content\_clear\_type\_cache()
> 1 votes

# Answer
Check which cache is relevant (e.g. cache\_content, cache\_views\_data) for this content and clear this cache explicitly. If you call cache\_clear\_all() without parameters you "only" clear the page and block cache. Take a look at the code of cache\_clear\_all() to see the details.
> 7 votes

---
Tags: 7, entities, caching
---


title: Module doesn't appear on update.php

text:
# Question
Title: Module doesn't appear on update.php
I wanted to add columns to my module schema, I added an update hook `hook_update_6031` however when I go to the update.php script my module isn't listed at all, not even as "no updates". Do I have to provide some hook to have my module be listed? I can't seem to find any documentation on how to write updates other than the function documentation for `hook_update` or looking at some other module code.

# Answer
> 7 votes
Some things to check:

* Is your update function placed in \[modulename\].module or in \[modulename\].install? It should be in the install file.
* Is the function really called hook\_update\_6031? in that case, replace 'hook' with the name of your module. For instance, an update function for the comment module could be called comment\_update\_6003.

If the above does not help, please update your question with the code of your update function. Also check the value in the `schema_version` column in the `system` table for your module - for the \[modulename\]\_update\_6031 function, it must not be less than 6031, but not -1.

---
Tags: hooks, updating
---


# Question
Title: Use term reference field in node--custom.tpl.php
I am building a website with Drupal 7, this website contains a blog. For some reasons I use a custom content type for blog posts call bog\_post. In this content type I add a "Term reference" field (is machine name is "field\_blog\_categories").

To custom the layout of blog post I override node--blog\_post.tpl.php. My problem is to display the term reference field. When I print the php var corresponding to that field "$field\_blog\_categories" I get :

```
Array ( [en] => Array ( [0] => Array ( [tid] => 8 ) ) )

```

As you can see the term name don't appear. I thought to get the name by tid. I try

```
taxonomy_term_load($field_blog_categories['en'][0]['tid'])

```

but it return nothing.

Any help to get the term name will be appreciate !

# Answer
> 1 votes
If `taxonomy_term_load()` return false then

* the supplied argument (tid) is either non-numeric
* Or there is no term with this id.

To check if there is any term against this id try

```
`taxonomy_term_load_multiple(array($tid), array());`

```

If `taxonomy_term_load_multiple()` returns empty array then it is clear there is no term with this `$tid`.

# Answer
> 1 votes
As an alternate approach, you could try using the function

```
<?php
/**
 * Get a list of all taxonomy terms
 */
function taxonomy_node_get_terms($node, $key = 'tid') {
    if(arg(0)=='node' && is_numeric(arg(1))) {
        static $terms;
        if (!isset($terms[$node->vid][$key])) {
            $query = db_select('taxonomy_index', 'r');
            $t_alias = $query->join('taxonomy_term_data', 't', 'r.tid = t.tid');
            $v_alias = $query->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
            $query->fields( $t_alias );
            $query->condition("r.nid", $node->nid);
            $result = $query->execute();
            $terms[$node->vid][$key] = array();
            foreach ($result as $term) {
                $terms[$node->vid][$key][$term->$key] = $term;
            }
        }
        return $terms[$node->vid][$key];
    }
}

/* just guessing at this function - it might need tweaking! */

function theme_preprocess_page(&$variables) {
    $node = node_load(arg(1));
    $results = taxonomy_node_get_terms($node);
    if(is_array($results)) {
        foreach ($results as $item) {
           $variables['your_taxonomy_terms'][] = $item->name;
        }
    }
}
?>

```

Then you could call $your\_taxonomy\_terms from your page template and it should return the names.

This is all based on the thread here -\> http://drupal.org/node/1072806

---
Tags: entities
---


# Question
Title: what POST values are required to update nodes containing CCK Date fields via cURL?
In brief:

I am tasked with maintaining a Drupal based site but can only access it via the web.

* I have several hundred nodes that are incorrectly formatted/missing content
* I wrote a class to simplify batch create and update activity via cURL and can successfully update moderately complex content types
* I cannot update nodes that have date fields and recurrence, when I try, the return is the form you'd find at /node/$id/edit with the fields populated with the same values I tried submitting and with this error:

+ An illegal choice has been detected. Please contact the site administrator.
    + An illegal choice has been detected. Please contact the site administrator.
    + The UNTIL value is required for repeating dates.
* I also cannot create a new node of any type that has a date field.

I am assuming the problem has something to do with the date fields. Pages, which do not have a date field, update without complaint.

The default values I'm submitting, in addition to taxonomy, cck text fields, the standard title and body, and identical start and end month/day/year values and are:

```
"field_date[rrule][FREQ]" => "NONE",
"field_date[rrule][UNTIL][tz]" => 'America/New_York',
"field_date[rrule][UNTIL][all_day]" => 1,
"field_date[rrule][UNTIL][granularity]" => 'a:3:{i:0;s:4:"year";i:1;s:5:"month";i:2;s:3:"day";}',
"field_date[rrule][exceptions][EXDATE][0][tz]" => 'America/New_York',
"field_date[rrule][exceptions][EXDATE][0][all_day]" => 1,
"field_date[rrule][exceptions][EXDATE][0][granularity]" => 'a:3:{i:0;s:4:"year";i:1;s:5:"month";i:2;s:3:"day";}',
"field_date[rrule][additions][RDATE][0][tz]" => 'America/New_York',
"field_date[rrule][additions][RDATE][0][granularity]" =>'a:3:{i:0;s:4:"year";i:1;s:5:"month";i:2;s:3:"day";}'

```

All of which were found in the POST values sent when manually saving one of these nodes both with and without changes.

I've been banging my head against the wall on this one for a couple of days now. Can anyone tell me what I'm doing wrong?

Thank you.

# Answer
All the CCK fields has access rights settings in actions-roles permission matrix. Normally the access is restricted. Please confirm the permission on date field for your role.

`An illegal choice has been detected. Please contact the site administrator.` is normally reported when some extra fields are added to the form which are not originally the part of form. It is a security measure from Drupal core.

I do not know how cURL request cycle maintains user session that should be associative with proper role that is allowed to edit date field.
> 1 votes

# Answer
The problem was ultimately quite trivial, the values I was submitting as `field_date[value][day]` and `field_date[value][month]` were always 2 digits (I was just exploding a date straight out of mysql), so anything that occurred after the 9th of Oct - Dec was fine but anything prior to that was invalid.
> 0 votes

---
Tags: entities
---


title: RSS Icon at browser's address bar

text:
# Question
Title: RSS Icon at browser's address bar
I m not using Drupal 7 with its default way. I don't publish in front page, since I use a view for the front page. I produce an RSS feed from a view.

How I can make the RSS icons appear at browsers' address bar?

# Answer
If you have a custom module, you can use drupal\_add\_feed, should work for both D6 and D7:

```
function CUSTOM_preprocess_page(&$vars) {
  drupal_add_feed(url('path/to/feed'), 'Feed Title');
  $vars['head'] = drupal_get_html_head();
}

```
> 1 votes

# Answer
You have to attach the feed to the page display.

It's an option in the feed configuration.
> 0 votes

---
Tags: views, feeds
---


# Question
Title: Deploying block settings as an update script?
I need to add a block to an existing Drupal site and would like to if possible automate the process using hook\_update\_N or something similar.

Specifically I'm referring to the position and region of the block relative to adjacent and following blocks. Is there a Drupal standard method to this process or do I simply need to use SQL to achieve this.

Is there a way to force a block in between others with some trick with the weights, or will I need to actively increment the weight of blocks below this in the same region?

Thanks for any advice!

# Answer
> 2 votes
You could do this if you like, but this is an unstable and hacky way of fixing your problem. The thing is that blocks can be rearranged at any time so using an update function to sort the block weights is not the best way to deal with this.

What you could do instead is to use the context module to deal with blocks. If offers a better interface to control blocks and allow you to display the same block in different regions. It also gives you a more advanced control of when blocks should be displayed, like display on all nodes of type x, or on these views etc.

In addition to all the nice features described above, contexts can be exported as features. This mean that you can with a click of a button create a module that have your block setup stored in code, including weights etc. If those blocks were to be rearranged, you could revert the feature back to the old state.

---
Tags: 6, blocks, deployment
---


# Question
Title: Randomize the result of a database query
I'm executing a query for which I want to randomize the results.

I tried with `$res=db_query("SELECT DISTINCT nid FROM content_type_event ORDER BY RANDOM()")`, but this doesn't work.

# Answer
For MySQL you can do

```
ORDER BY RAND()

```

To order by random, for PgSQL `RANDOM()` instead should yield the desired result.
> 7 votes

# Answer
googletorp's answer is correct, I can only offer some notes:

* Keep in mind that this approach will be relatively heavy on the database - ordering by RAND() will have to build temporary structures to sort **all** of the records for each time you execute this query. Therefore this approach should be used if you really do need to sort all of the records randomly. If you are getting only one random record (or a few) then much more efficient approach would be to generate a random *nid* and select on it (where existing index can be used; there are different strategies on this - you might still do it on the database side, or you might do it from the application; query execution time might be different by two orders of magnitude).
* Next the DISTINCT might slow things down further as it also have to build temporary index to guarantee DISTINCT values; here you might be better of by selecting from nodes and just checking if a record EXISTS in content\_type\_event (but YMMV here)

As always, it is good to have a few variants and test on real data.
> 6 votes

---
Tags: database
---


# Question
Title: Automatic alias overriding manual alias on each edit
Does anyone have an issue with Automatic alias, where the setting keeps turning back to auto on each edit of a node?

What we would like to achieve is

a) some node paths should be generated automatically from the title and remain automatically managed

b) for other paths we want to override the alias

The problem is only with b, where after any edit to the node the alias behavior reverts back to a.

How to get desired behavior?

# Answer
> 3 votes
Go to admin/build/path/pathauto on your site, open the 'General settings' fieldset and select 'Do nothing. Leave the old alias intact.' as update action. That should be all.

---
Tags: 6, path-aliases
---


title: Views, path problem

text:
# Question
Title: Views, path problem
My view path is: bartender/profiles/friends/%

In View UI if I provide argument everything works ok.

But in real when I go to ex. site.com/bartender/profiles/friends/20 I get a page from site.com/bartender url.

Could somebody help me solve this issue?

# Answer
The Sub-path URL Aliasing module causing problem. After turn off all works fine.
> 3 votes

# Answer
Drupal menu system strictly follow the menu paths.

According to my experience you do not need to add `%` sign while defining path.

Define your argument by adding an entry from Views UI (Argument Section)

`Provide default argument` to deal the scenario without page argument

Access is by default `unrestricted`. Check is as well

---

Drupal menu system travels from bottom to top.

e.g. path a/b/c/d is not valid then the content is showed from a/b/c similarly the process goes upward.

Your example is evident that your views is no receiving arguments and `bartender/profiles/friends` and `bartender/profiles` are invalid paths.
> 4 votes

---
Tags: views, 6, uri
---


# Question
Title: embedding a block inside a views template file
This question could be asked in numerous ways, so I'm just going to explain my situation.

I currently have a block that works fine listing any child nodes (node reference is used between the nodes). This works as it uses an Argument for the Node ID so it can list all the children in a nice list.

However, I wish to have this very list of child nodes - displayed in a sort of "Teaser List" from a seperate view. The reason this "new" view wont work - is because there is currently no Node ID to reference the children - as the block doesn't sit on the parent page anymore.

So my initial solution was to embed a view using views\_embed\_view with something like:

```
print views_embed_view('show_units_display', 'block_1', $node->nid);

```

And I would have this in my views template file for each result row. But seeing as the view itself sits on an entirely seperate page - no Node ID is passed here and there no results are displayed!

My overall outcome would look like this:

Node 1 - title
Node 1 - body

-- display list of children of node 1 here --

Node 2 - title
Node 2 - body

-- display list of children of node 2 here --

And so on...

Any help would be brilliant!
Cheers,
Garry.

# Answer
In your Views row template, you should have access to `$row` which store all the records retrieved for this row and especially `$row->nid` which is the nid you want to pass it to the block of your row-footer view.
> 1 votes

# Answer
A Computed Field on the node itself can also pass the NID to a view, regardless of the page it's displayed on.

Add a Computed Field to the node type.

in Computed Code:

```
$node_field[0]['value'] = $node->nid;

```

in Display Format:

```
$display = views_embed_view('VIEWNAME','DISPLAY', $node_field_item['value']);

```

If you store it in the database, then the field can be called in via Views.
> 2 votes

---
Tags: nodes, views
---


# Question
Title: How to integrate Field collection module in Views?
I have created fields and grouped together with Field collection module. I have attached the group field (containing 4 fields), to user account settings in : `admin/config/people/accounts/fields`.

Now I am trying to display the content of this field-collection into a view, however I can not do it!

Views 7.x-3.0-beta3 do not allow me to specify the current user and to get in a table the field-collection contents. How can I get this contents into a view-kind table?

**UPDATE:** I have seen that Field collection module has a patch for Views module here: Add Views Relationship to Field Collection - patch attached which is already included in Field collection 7.x-1.x-dev. This allows me to have access at field in collection form Views, however is not allowing me to set a custom filter for the entity of which I associate the field collection. I my case is the user ID.

How can I have access to that form views ?

# Answer
> 10 votes
What kind of view are you creating?

Since the collection is being used in the user entity you should create a user view. This will allow you to set the user id filter you want to set.

Once you create that user view you will need to add the field\_collection relationship to display those appropriate field.

This is assuming you are using the latest field\_collection - dev version. Hope this helps.

---
Tags: 7, entities, nodes, views
---


# Question
Title: Select on which page a view has to be display
I am new to the Views module in Drupal 7. I enable the Taxonomy Term view and customize it a bit. For now the view is displayed in the default page of my theme in the main content region. But I would like this view to be displayed in a custom page defined by my theme on a particular region. It seems to be an easy task but I can't figure how to do that.

# Answer
It is easy, Edit your View and Click on Add (A popup near upper left) and choose `Block`

This newly created block will inherit all the settings from your existing view display.

You can Override any setting for your block display.

Choose appropriate template relevant to block following Theme: Information

Save your view and head on to block listing page to adjust your newly created block.
> 0 votes

---
Tags: views
---


# Question
Title: What is the machine name for the Date Posted?
I'm using Views and have it set to fields. Can anyone tell me what the machine name of `Content: Post date` is? I used `Time ago` in my selection.

# Answer
> 1 votes
If you are talking about the 'ID' of the `Content: Post date` in Views, it is: `created`

You can find this under the `Theme: Information` link under the 'Advanced' settings block (in D7/Views 3) or the 'Basic settings' block (in D6/Views 2). After clicking that link, find the name of the field and find the ID in parenthesis next to the field name.

Example: In this case you should find `Field Content: Post date (ID: created)`

# Answer
> 1 votes
Another smart trick to know identifiers is the following.

Hover your field title (e.g. "Taxonomy: Term") from your view setting, and focus on the status bar of your browser.

In my case, I get `http://example.com/#overlay=%3Fq%3Dadmin/structure/views/nojs/config-item/my_view/page/field/name`.

Look into the last 4 items:

* my\_view: View Identifier
* page: Display Identifier
* name: Field Identifier

---
Tags: 7, datetime
---


# Question
Title: Is it possible to combine RSS feeds and other stories in the same view?
I subscribe to an RSS feed I would like to post in the same view as some user-generated stories and I would like both types of content to display as a uniform list. Can that be easily done?

# Answer
Can you give more details? Do you mean importing a feed into your website and then displaying its contents alongside your own? You'd need the Feeds module to do that.

UPDATE: Yes, this is possible. You need the Feeds module, and to create a content-type to hold the feeds. When displaying your view, use Filters to narrow it down to just your user-entry content-type and the Feeds-info content-type, and they will both display (in whatever order you set, the default is posted date).
> 1 votes

---
Tags: views, entities, feeds
---


# Question
Title: How to make Feeds import only one post at a time when cron run?
I have a website which will import many images through Feeds. But Feeds import too much posts which affect the bandwidth.

I want Feeds import only one post at a time when cron run.

The setup:

* feeds-6.x-1.0-beta10
* Drupal 6.20

# Answer
> 1 votes
There's no way (without hacking the Feeds module) to set this. You can affect how often the Feed updates, so if it's a feed with lots of posts set it to update more often and run cron more often, and that way fewer items will be imported per run because there won't be large amounts of new data to import each time.

---
Tags: feeds
---


# Question
Title: Change the number of entries depending on a theme setting
I have a theme setting that allows the administrator users to specify how many teasers should be shown on the home page by selecting a number from 1 to 4 (through a `<select>` field). Is it possible to reference this variable so I can use it in Views? In that way, I can let Views check that value in the theme settings, then display the number of entries accordingly.

# Answer
> 1 votes
You could do this, but it will require that you know a bit about views exports.

You would have to create the view in code, by exporting it, this could be done with features or the views alone and use `hook_default_views`.

Once views read the view from code instead of the database you could insert a dynamic value for the number of items shown by the view, gotten from the theme setting. You would need to make sure that the value is formatted the way views expects it.

One important note. You can't make any changes to the way, as it will stop reading from the code and use the database instead. When this happens the dynamic value will be replace with a static one.

# Answer
> 1 votes
Adapted from https://stackoverflow.com/questions/4739672/select-number-of-items-in-drupal-views/4742406#4742406.

You can accomplish this with `hook_views_pre_build` by altering the `pager` property. `print_r` it to see what is available. If your case, you would need to get the theme variable into the hook, but this does somewhat do things backwards (modules should be theme agnostic).

The code would look something like:

```
function MYMODULE_views_pre_build(&$view) {
  $perpage = some_way_to_get_the_variable();

  if (is_numeric($perpage) && (int) $perpage > 1) {
    $view->pager["use_pager"] = FALSE;
    $view->pager["items_per_page"] = (int) $perpage;
  }
}

```

The link above to SO has a more a more generic version.

---
Tags: 7, views
---


# Question
Title: What module does this site use to handle its great badge system?
Is this a functionality that exists within the existing badge module, or is it anything else?

# Answer
> 4 votes
This site (stackexchange.com) is not built with Drupal, but if you're looking for similar features in Drupal, check out User Badges, possibly in combination with Userpoints and/or Rules.

---
Tags: 7, users
---


title: views pager showing X results per page

text:
# Question
Title: views pager showing X results per page
I was wondering if anyone knew how to go about adding a drop down or even a list of links to help change the amount of views results per page.

Ideally, when there's a lot of results you would want to be able to choose:

* 5 per page
* 10 per page
* 20 per page
* 50 per page

A drop down box would be brilliant for this; it is the sort of thing you see on many search forms.

# Answer
Have a look at Steven Ward's site for a bit of a hacky way to do what you're looking for.
> 3 votes

# Answer
This feature is now built into Views 3.
> 1 votes

---
Tags: views, search, paging
---


title: Example of hook_file_download

text:
# Question
Title: Example of hook_file_download
How do I restrict the access to certain files based on their content type? I have the download section for registered users, and I want to prevent them to post links somewhere outside my site.

Is implementing `hook_file_download()` sufficient?

I tried this code and it's enough for my purpose, but the documentation of `hook_file_download()` doesn't help much.

```
function customize_file_download($uri) {
  global $user;
  if (!array_intersect(array('administrator','editor','expert','verified'), array_values($user->roles))) {
    return −1;
   }
}

```

# Answer
> 8 votes
There is a couple of hooks in drupal 7 to restrict access to files.

One thing you have to realized is that these access hooks are only going to work if your download method is private, and the files are in your private path.

As you mention in your question there is a hook\_file\_download that should work in your case (assuming the file is private). This is not going to work if the file, someone is linking to, is somewhere public such as sites/default/files/abc123.txt.

If you happened to be uploading these private files in a field, then hook\_file\_download\_access would seem more appropriate. This will give you the field that the file belongs to and also the related entity that this field is being used on so you should be able to do more complicated logic such as calling the the appropriate access function to check if the user has access to the field instead of having a hard-coded list in the code.

# Answer
> 0 votes
A link to a file is just that - a link. I don't believe there is a way to determine the location of the link. You might be able to look at headers, but this will probably not work.

If you can determine the location of the link to the file, using hook\_file\_download will be a good choice for access control.

---
Tags: 7, entities, hooks, files
---


title: Storing third party passwords

text:
# Question
Title: Storing third party passwords
What is the standard or recommended way to store third party passwords in Drupal? Specifically, I want to use oAuth to authenticate a user to Google, and do not want to ask users to type in their passwords each time they access their accounts.

# Answer
**You don't store 3rd party passwords - nor should you get them.**

The whole idea behind oAuth is that you will never get the email and password of the user that signed in with google. What you get instead is a token that is valid for a specific period of time for that user. It depends on the provider how long the token is valid, but it could be indefinitely. The smart thing about oAuth is that if you user has an active session on the site you are accessing and have granted your site access, he wont need to do anything. The browser will use his cookie for access and the site will allow you to do what you need since the user already has granted you the access.

So what you need to do is to store the token, typically something that looks like a md5 hash, the username and the site. This can be stored in the database, I would use a custom table unless you have a module that handles this for you.
> 3 votes

---
Tags: authentication-authorization, users
---


# Question
Title: Where do I store classes and ids that the user inputs in my custom module?
I am creating a module that I would like to submit to the drupal.org repository. In the admin section of the module there are various input fields where the user is able to enter classes and ids for various elements that appear on specific nodes. It's basically a module that enables the user to do theming that would otherwise require custom code.

Since I'm not a Drupal rock-star in any way, and I have only worked in custom code and website specific modules, I have a very important question:

**How do I store the classes/ids that the module's user will submit?**

I guess that there are 3 options here:

1. Store the classes/ids in a module-specific table in the database
2. Store the classes/ids in the "Variable" table of the database
3. Store the classes/ids in a file, in the module's directory

I have some pros/cons in mind about each case (e.g. I don't like the idea that a theming element would be stored in the database) but I would like your input too: which one of the methods above is the best and drupal-friendly? If I missed an option, please feel free to list it.

# Answer
> 2 votes
Saving the classes in a Drupal persistent variables would make sense if the module just need to save a few classes; if the module allows the user to save an undefined number of classes, then saving them in a custom database table is what I would do.

As far as I remember, modules are not allowed to write in their own directory. Saving in a file data that needs to be retrieved seems less performant than using the database, though, especially if the code needs to get specific data, and not all the saved data.

# Answer
> 2 votes
Of your three options, 2 would be a huge burden to a site in performance, and 3 will likely be a security issue. So I'd go with 1.

For reference, see the Block Class module.

# Answer
> 1 votes
I recommend option 1 too. Why shouldn't classes be in the database? That is node related context information, just like some comment related flags per node (show comments, allow comments, ..) for example.

You can store it in a separate table and reference it to the nid.

Then implement hook\_entity\_prepare\_view() (better than hook\_node\_load(), because only invoked for nodes which are actually going to be displayed) and load those classes in a single query for all $entities if $type is node.

The variables table is loaded into memory on every request (completely), you should only store information there that you need frequently.

---
Tags: database
---


title: Views attach not working in my theme

text:
# Question
Title: Views attach not working in my theme
I can't seem to get views attach to work in the theme I've created... is there maybe a line of code I'm missing that needs to be included in page.tpl.php for it to work?

Thanks!

# Answer
Pretty sure you can just do:

```
<?php
$viewName = 'WHATEVER';
print views_embed_view($viewName);
?>

```
> 3 votes

---
Tags: views
---


title: Drupal and long-polling/sockets

text:
# Question
Title: Drupal and long-polling/sockets
I'm looking for some ideas of how best to cater for the following scenario: I have a facebook-style feed on the front of a site that is updated with user content regularly, and just like facebook I want the page to update as nodes are submitted to the site.

So it looks to me like a classic use case for a bit of long-polling, or even using some of those new fang-dangled web sockets. But how am I going to integrate this with drupal?

There's no way I can have 20 let alone several hundred users long polling drupal directly - it would lock up every php process my system could provide.

I've been considering writing a tiny wee node.js program which would would handle all the long-polling connections and would watch the drupal node table directly. When updated, node would query drupal and proxy the request back to the clients. But this seems like a pretty awful solution to me.

Another idea I had was to load the current maximum node nid number along with the intial request, and then somehow also advertise this number via long-polling - if the advertised number changes, it would trigger the client to make a request. But I'm not sure how to implement this advertising.

So what other options are there?

# Answer
> 5 votes
Yes, implementing comet/long polling in Drupal is a bad idea.

There already is a node.js project that you could use: Drupal node.js integration.

The design principle of that module is that node.js does not contain any logic (to avoid duplication of logic in PHP and JS) but is only reponsible for keeping a connection open to your users. You then send notifications to node.js in the usual hooks (like hook\_node\_save()) which forwards it to your users.

---
Tags: ajax
---


title: CKeditor and Input Formats confusion

text:
# Question
Title: CKeditor and Input Formats confusion
Why is there a 'Security Filters' section within the CKEditor configuration settings?

My understanding is that this is all set within the normal Drupal input formats section (admin/settings/filters). Do the CKEditor input configs replace this when the editor is present in a field?

:-/

# Answer
Sorry for posting link answer but, there is a complete tutorial here.
> 2 votes

---
Tags: wysiwyg
---


# Question
Title: Ajax Search Field with labels for node types
I'd like to have a search field with ajax and some kind of label for the node type. Similar to http://www.finanzen100.de . Is there any module or other ways of getting this for drupal 7 (or 6)?

# Answer
> 1 votes
Can Inline Ajax Search cover your needs?

---
Tags: search
---


title: Dynamic links block

text:
# Question
Title: Dynamic links block
I want to make a block with dynamic links. An example path would be http://example/node/7/addreview The number 7 will change depending on what node it's viewing. So if it's viewing node 14 then it should be http://example/node/14/addreview. How can i do this?

# Answer
> 1 votes
Enable module `PHP Filter` it is part of drupal core and disabled by default

Add a new (custom) block (/admin/build/block/add)

Add following code in the body

```
<?php
    if(arg(0) == 'node' && is_numeric(arg(1)){
        print l('Add review', 'node/'. arg(1) . '/addreview');
    }
?>

```

Set `Input Format` type to `PHP Code`

Save your block with appropriate visibility conditions

Associate your block to some region beside main content area.

---
Tags: blocks
---


# Question
Title: Placing the comment form on a separate page
Is it possible to **place the comment form for a content type on a separate page?** I have some teasers on the home page and since I did them using Views, I need to find a way for people to add comments to it. If I can place a link which opens another page with *just* the comment form then that would be great.

# Answer
> 9 votes
Drupal has this built in, the link you are after is `comment/reply/[nid]`.

# Answer
> 9 votes
The page at admin/structure/types/manage/\[content-type\] contains the option "Show reply form on the same page as comments."

When you deselect that option, the node pages appear as in the following screenshot.

Once you click on "Add new comment," you are redirected to comment/reply/\[node-id\]#comment-form, which shows the following form:

When the option is selected, the node pages appear as in the following screenshot.

---
Tags: 7, comments
---


# Question
Title: How do I change the output of theme_comment_submitted()?
How to change the default theme of comment\_submitted in drupal?

**Input:**

$variables\['submitted'\] = theme('comment\_submitted', $comment);

**Output**

**My expected result is**

* To print the **Name in first** and **time in second**.
* **Should not truncate**.

How can this be done?

# Answer
Add a function in your `template.php` located in your theme's directory.

```
function phptemplate_comment_submitted($comment){
  return t('Submitted on @datetime by !username.',
    array(
      '!username' => theme('username', $comment),
      '@datetime' => format_date($comment->timestamp)
    ));
}

```
> 2 votes

# Answer
You can override any theme function implementing hook\_theme\_registry\_alter() in a module.

```
function mymodule_theme_registry_alter(&$theme_registry) {
  if (isset($theme_registry['comment_submitted'])) {
    $theme_registry['comment_submitted']['function'] = 'theme_mymodule_comment_submitted';
  }
}

```

In this case, as what you want is to override a string used by a module, String Overrides could help you. You just need to replace "Submitted by !username on @datetime." with "Submitted on @datetime by !username."
> 1 votes

---
Tags: theming
---


# Question
Title: Paging the list of comments, and getting the comment count
I am getting all the comments listed in the same page. How can I do the paging concept for comments?
How do I get the comment count?

# Answer
> 3 votes
Paging on comments is provided in Drupal Core without any contribute modules.

If you go to your content type configuration screen:

* D6 Path: admin/content/node-type/\[node-type-name\]
* D7 Path: admin/structure/types/manage/\[node-type-name\]

You will see there's a Comment field-set/tab(d7) with some options. The option you want to check out is the comments per page setting. Select the number you'll like for when a page should break and save your settings. Once you're comment have pass that threshold you will see a pager for your comments.

Now for the comment counts there a variable available to you in both Drupal 6 and 7 in the node template. The name of that variable is $comment\_count.

---
Tags: comments, paging
---


# Question
Title: How to clear cache bins via the admin interface
Drush will allow you to selectively clear caches. CSS/JS or views for example.

Is there a way to do this via the admin interface, or a contrib module to do it? I don't have access to drush on a server and the cache rebuild is not reliable so it would be nice to just clear the cache bin that I need to.

# Answer
In D6 install the admin menu. By clicking on the favicon on the left hand side of the menu you can clear all/seleted caches.
> 3 votes

# Answer
In Drupal 7 there is a new shortcut menu; simply add a shortcut to the performance page.
> 1 votes

# Answer
I usually just add a item somewhere in the admin menu, and create my own callback that does cache\_clear\_all on the table I want. Normally I do this when I have my own cache table in a custom module, so this gets lumped with all the other admin menu entries for the module.
> 1 votes

---
Tags: 6, caching
---


title: How to render a form in table layout

text:
# Question
Title: How to render a form in table layout
What is the Drupal way of presenting multi-row, multi-column module data to the user in Drupal 6? Nothing jumped out in the API documentation. I was googling for some answers, but they all applied to earlier versions or referenced dead modules.

Am I correct in thinking that the out-of-the-box functionality for the forms API is basically a key::value editing interface? If that's the case, is there a current, well-maintained module to do this, or should I present this data in a different way for the user -- perhaps a view?

**Edit** I would like this table to have form features for editing the data, such as insert, changing cell data, etc. That's why I thought it would be natural for it to reside in the module's settings, but that table functionality does not appear to be there.

# Answer
A little bit tricky

```
function your_form(){
  $form = array();
  ...
  $record_ids = array();

  foreach($record_set as $record){
      $record_ids[$record['id']] = ''; // Collect ids of your record as index
      $form['column1'][$record['id']] = array('#value' => $record['field1']);
      $form['column2'][$record['id']] = array('#value' => $record['field2']);
      $form['column3'][$record['id']] = array('#value' => $record['field3']);
  }

  $form['select'] = array(
      '#type' => 'checkboxes',
      '#options' => $item_ids,
  );

  $form['#theme'] = 'render_your_form'; // Theme registry function to render this form
}

```

Define theme\_registry

```
function your_module_theme(){
   ...
   $theme['render_your_form'] = array(
       'arguments' => array('form' => array()),
   );
   return $theme;
}

```

Now write your theme handler

```
function theme_render_your_form($form=array()){
   $head = array('Select', 'Title Col 1', 'Title Col 2','Title Col 3');
   $rows = array();
   foreach(element_children($form['select']) as $id){
       $fields = array();
       $fields[] = drupal_render($form['select'][$id]); //This will render a checkbox, omit if not required
       $fields[] = drupal_render($form['column1'][$id]);
       $fields[] = drupal_render($form['column2'][$id]);
       $fields[] = drupal_render($form['column3'][$id]);
       $rows[] = $fields;
   }
   $output = theme('table', $head, $rows); // Theme as table output
   $output .= drupal_render($form); // Render rest of form components. (For D6)
   $output .= drupal_render_children($form); // Render rest of form components (For D7)
   return $output;
}

```
> 7 votes

---
Tags: 6, forms, theming
---


# Question
Title: Image height/width not saved using CKEditor and Full HTML input format
I just upgraded a Drupal site from 5.22 to 6.22. Everything is working except for one small problem. I replaced FCKEditor with CKEditor using CKFinder to manage file uploads.

The problem is that when I insert an image into the CKEditor and adjust the width/height, it is not saved.

I am using Full HTML for the input format, so I don't understand why it's not working.

# Answer
Looks like this might be a known issue. See this thread for info: http://drupal.org/node/731068
> 1 votes

---
Tags: wysiwyg, media
---


# Question
Title: Getting the uid from user name for a view argument
I'm loading content from a third party system to Drupal using the Feeds and Data modules. Drupal will be used as an intranet, the users will be able to log in and see their account records (the data I'm getting into Drupal). One of the fields has the user name (not the user id), so in the external system a record can be referenced to each user.

In views is posible use the uid as an argument and show content that references to that uid. Is there a way that I can use the user name as an argument and show the content if that user is logged in or viewing his/her user profile?

Data module does not allow relationships when creating a view.

I suppose I can insert PHP code, use the user name then load de uid, and use de uid as validator in views, I'm not a PHP expert and I'm not sure if that is the correct way to do it.

Thanks in advance for your advices.

# Answer
Use the Data name argument to filter the results by. Each content field has it's own argument that you can choose to filter the results by.

(edit: reply to comment) Let's say that your drupal username is user3 with a UID of 3. The user ID of the external data will be user3? So when the user goes to mysite.com/user/3 the argument will be 3 which doesn't help with the external data because that needs to be mapped to user3? If the user ID of the external data is 3 then you can use data: field\_userID or whatever it is and get arg(1) using provide default value from PHP code, page manager or Views Arguments from Context. Now, if you to map the Drupal username to the external data username/user ID which is user3 then use provide default value from PHP code, get the global $user variable and use $user-\>name for the argument. This maps the user's name to the database column in the data table and returns (filters) all results/ database rows with that username in that column.

Don't validate it until you get it working.

```
global $user;
return $user->name;

```

or

```
return arg(1);

```
> 1 votes

---
Tags: users, views
---


title: Testing for taxonomy

text:
# Question
Title: Testing for taxonomy
On my website, I have used the Taxonomy to created different sections. Each section has its own "contact us" page. I want to create a variable that will create a path to the relevant contact page. That way I can print the variable in taxonomy-term.tpl.php, node.tpl.php and page.tpl.php files to print the path dynamically.

How can I test for the taxonomy, and then change the value of the variable accordingly?

I've looked around for an answer and the closest I could find was How to move custom code into template.php. However, it requires a taxonomy reference field to present to perform the test and so wont work on the main taxonomy index pages (which cannot have taxonomy field references).

EDIT: Please note: The contact us page is just a normal node with telephone numbers on it. It is not the Drupal contact us form.

# Answer
> 1 votes
There is a Drupal Dojo video that answers this exact question. It is done in Drupal 6 but might give you some clues how to accomplish this in Drupal 7.

(edit: Response to comment) Although it might add complexity to developing your website, you can use the Context module to trigger block visibility based on certain criteria such as a View being viewed or a taxonomy term page being viewed. Keep in mind that if the Context module is used with all blocks disabled in the block UI it gives a performance boost to the website.

---
Tags: taxonomy-terms, theming
---