We needed the ability to have more complex filters for our content, namely:

  • comparison operators other than 'is' and 'is not' (e.g. 'is before', 'is after', 'contains', etc); and
  • input fields other than select lists (like 'date', or 'textfield')

To do this the filter array returned by hook_node_admin_filters() was extended to support a 'comparisons' parameter for listing the available comparisons to choose from. If not included it would use the default: array(1 => 'is', 0 => 'is not'). Additionally a 'type' parameter can be used to specify and alternative form element type.

For example:

function hook_node_admin_filters() {
  return array(
    'created' => array(
      'type' => 'date',
      'title' => t('Created Date'),
      'callback' => 'node_filter_created',
      'comparisons' => array('=' => 'is', '<>' => 'is not', '<' => 'is before', '>' => 'is after'),
    ),
  );  
}

Allowing for additional element types means we can no longer assume that there is an 'empty' state for that type to exclude it from queries (like what happens with the select type). To work around this the interface was changed to support the dynamic adding and dropping of filters as logged in #239069: Improve filter UI

The included patch was made against HEAD.

The patch was developed by IDG Australia

Comments

triclops’s picture

New patch.

Changes made:

  • Removed the 'weight' parameter from the filter hook
  • Added sorting to the list of available filters to add
  • Made the active filters use a '#weight' based on the order they were added in
  • Removed the empty value from select lists because it's now redundant