2

If there is another way to check if a list is empty, that is fine too.

2

Make a custom module eg. customrules and create customrules.rules.inc in this module. In customrules.rules.inc place following code:

/**
 * Implements hook_rules_action_info().
 */
function customrules_rules_action_info() {
  return array(
    'customrules_list_length' => array(
      'label' => t('Get length of list'),
      'group' => t('Data'),
      'parameter' => array(
        'list' => array(
          'type' => 'unknown',
          'label' => t('List'),
        ),
      ),
      'provides' => array(
        'list_length' => array(
          'type' => 'text',
          'label' => t('List length'),
        ),
      ),
    ),
  );
}

/**
 * The action for 'customrules_list_length'
 */
function customrules_list_length($list) {
  return array(
    'list_length' => is_array($list) ? count($list) : NULL,
  );
}

Now you should be able to use this action to get the list length

2
  • That's exactly what I did. Someone should post that to d.o though. – Gaelan Oct 18 '12 at 23:21
  • You can change the 'type' under the second 'provides' to other types (I'm using integer) if that is required. – Mrweiner Feb 17 '16 at 17:56
1
  1. You might be able to doing without any coding using a view to just return the count of your list and if you have different lists you might want to use the views argument (D6) or the contextual filters (D7) to only use one view for all of them.

  2. Using Rules and Views Integration if D6 or Views Rules if D7 you will be able to access the view from rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.