You are here

function flag_rules_action_info in Flag 7.3

Same name and namespace in other branches
  1. 6.2 includes/flag.rules.inc \flag_rules_action_info()
  2. 6 includes/flag.rules.inc \flag_rules_action_info()
  3. 7.2 flag.rules.inc \flag_rules_action_info()

Implements hook_rules_action_info().

File

./flag.rules.inc, line 169
Rules integration for the Flag module.

Code

function flag_rules_action_info() {
  $param_defaults = array(
    'flagging_user' => array(
      'type' => 'user',
      'label' => t('User on whose behalf to flag'),
      'description' => t('For non-global flags, this is the user on whose behalf to flag the object. In addition, if checked below, the access permissions to the flag are checked against this user.'),
    ),
    'permission_check' => array(
      'type' => 'boolean',
      'label' => t('Skip permission check'),
      'description' => t('Whether to ignore permissions of the user on whose behalf to flag.'),
      'restriction' => 'input',
    ),
  );
  $items = array(
    'flag_trim' => array(
      'label' => t('Trim a flag'),
      'base' => 'flag_rules_action_trim',
      'parameter' => array(
        'flag' => array(
          'type' => 'flag',
          'label' => t('Flag'),
        ),
        'flagging_user' => array(
          'type' => 'user',
          'label' => t('User whose flag to trim'),
          'description' => t('For non-global flags, this is the user whose flag to trim. (For global flags, this argument is ignored.)'),
        ),
        'cutoff_size' => array(
          'type' => 'integer',
          'label' => t('Flag queue size'),
          'description' => t('The maximum number of objects to keep in the queue. Newly flagged objects will be kept; older ones will be removed. Tip: by typing "1" here you implement a singleton.'),
        ),
        'trim_newest' => array(
          'type' => 'boolean',
          'label' => t('Trim newest flags'),
          'description' => t('Checking this will trim the newest flags.  This will prevent new flags once a limit is reached.'),
        ),
        'permission_check' => $param_defaults['permission_check'],
      ),
      'group' => t('Flag'),
      'access callback' => 'flag_rules_integration_access',
    ),
    'fetch_overall_flag_count' => array(
      'label' => t('Fetch overall flag count'),
      'base' => 'flag_rules_action_fetch_overall_flag_count',
      'parameter' => array(
        'flag' => array(
          'type' => 'flag',
          'label' => t('Flag'),
        ),
      ),
      'provides' => array(
        'overall_flag_count' => array(
          'label' => t('Overall flag count'),
          'description' => t('During a flagging/unflagging event the count
            will take into account the current flagging/unflagging procedure.'),
          'type' => 'integer',
        ),
      ),
      'group' => t('Flag'),
      'access callback' => 'flag_rules_integration_access',
    ),
    'fetch_entity_flag_count' => array(
      'label' => t('Fetch entity flag count'),
      'base' => 'flag_rules_action_fetch_entity_flag_count',
      'parameter' => array(
        'flag' => array(
          'type' => 'flag',
          'label' => t('Flag'),
        ),
        'entity_type' => array(
          'type' => 'text',
          'label' => t('Entity type'),
          'options list' => 'flag_rules_get_flag_types',
          'restriction' => 'input',
        ),
      ),
      'provides' => array(
        'entity_flag_count' => array(
          'label' => t('Entity flag count'),
          'description' => t('During a flagging event, the count
            will take into account the current flagging procedure. For
            an unflagging event, the count will NOT yet be decreased for the
            current unflagging procedure.'),
          'type' => 'integer',
        ),
      ),
      'group' => t('Flag'),
      'access callback' => 'flag_rules_integration_access',
    ),
    'fetch_user_flag_count' => array(
      'label' => t('Fetch user flag count'),
      'base' => 'flag_rules_action_fetch_user_flag_count',
      'parameter' => array(
        'flag' => array(
          'type' => 'flag',
          'label' => t('Flag'),
        ),
        'user' => array(
          'type' => 'user',
          'label' => t('User'),
        ),
      ),
      'provides' => array(
        'user_flag_count' => array(
          'label' => t('User flag count'),
          'description' => t('During a flagging event, the count
            will take into account the current flagging procedure. For
            an unflagging event, the count will NOT yet be decreased for the
            current unflagging procedure.'),
          'type' => 'integer',
        ),
      ),
      'group' => t('Flag'),
      'access callback' => 'flag_rules_integration_access',
    ),
  );
  foreach (flag_get_types() as $type) {
    $entity_info = entity_get_info($type);
    $label = $entity_info['label'];
    $items += array(
      'flag_fetch_' . $type . '_by_user' => array(
        'label' => t('Fetch @label flagged by user', array(
          '@label' => $label,
        )),
        'base' => 'flag_rules_action_fetch_entity_by_user',
        'parameter' => array(
          'flag' => array(
            'type' => 'flag',
            'label' => t('Flag'),
            'flag_type' => $type,
            'description' => t('The flag to check for.'),
          ),
          'flagging_user' => array(
            'type' => 'user',
            'label' => t('User who flagged the @label', array(
              '@label' => $label,
            )),
            'description' => t('For non-global flags, this is the user who flagged the @label. (For global flags, this argument is ignored.)', array(
              '@label' => $label,
            )),
          ),
        ),
        'provides' => array(
          'content_flagged_by_user' => array(
            'label' => t('Content flagged by user'),
            'type' => 'list<' . $type . '>',
          ),
        ),
        'group' => t('Flag'),
        'access callback' => 'flag_rules_integration_access',
      ),
      'flag_flag' . $type => array(
        'label' => t('Flag a @label', array(
          '@label' => $label,
        )),
        'base' => 'flag_rules_action_flag',
        'parameter' => array(
          'flag' => array(
            'type' => 'flag',
            'label' => t('Flag'),
            'flag_type' => $type,
            'description' => t('The flag to check for.'),
          ),
          $type => array(
            'type' => $type,
            'label' => $label,
          ),
        ) + $param_defaults,
        'group' => t('Flag'),
        'access callback' => 'flag_rules_integration_access',
      ),
      'flag_unflag' . $type => array(
        'label' => t('Unflag a @label', array(
          '@label' => $label,
        )),
        'base' => 'flag_rules_action_unflag',
        'parameter' => array(
          'flag' => array(
            'type' => 'flag',
            'label' => t('Flag'),
            'flag_type' => $type,
            'description' => t('The flag to check for.'),
          ),
          $type => array(
            'type' => $type,
            'label' => $label,
          ),
        ) + $param_defaults,
        'group' => t('Flag'),
        'access callback' => 'flag_rules_integration_access',
      ),
    );
    $items['flag_fetch_users_' . $type] = array(
      'label' => t('Fetch users who have flagged a @label', array(
        '@label' => $label,
      )),
      'base' => 'flag_rules_action_fetch_users',
      'parameter' => array(
        'flag' => array(
          'type' => 'flag',
          'label' => t('Flag'),
          'flag_type' => $type,
          'description' => t('Choose the flag for which to fetch the users.'),
        ),
        $type => array(
          'type' => $type,
          'label' => $label,
        ),
      ),
      'provides' => array(
        'users' => array(
          'label' => t('Users who flagged'),
          'type' => 'list<user>',
        ),
      ),
      'group' => t('Flag'),
      'access callback' => 'flag_rules_integration_access',
    );
  }

  // For backward compatibility sake. This was the original name of the
  // 'fetch node by user'.
  $items['flag_fetch_entity_by_user'] = $items['flag_fetch_node_by_user'];
  $items['flag_fetch_entity_by_user']['label'] .= ' ' . t('(Legacy)');
  return $items;
}