function RulesEntityController::applyConditions

Override to support having events and tags as conditions.

See also

EntityAPIController::applyConditions()

rules_query_rules_config_load_multiple_alter()

File

includes/rules.core.inc, line 75

Class

RulesEntityController
Make sure loaded rule configs are instantiated right.

Code

protected function applyConditions($entities, $conditions = array()) {
    if (isset($conditions['event']) || isset($conditions['plugin'])) {
        foreach ($entities as $key => $entity) {
            if (isset($conditions['event']) && (!$entity instanceof RulesTriggerableInterface || !in_array($conditions['event'], $entity->events()))) {
                unset($entities[$key]);
            }
            if (isset($conditions['plugin']) && !is_array($conditions['plugin'])) {
                $conditions['plugin'] = array(
                    $conditions['plugin'],
                );
            }
            if (isset($conditions['plugin']) && !in_array($entity->plugin(), $conditions['plugin'])) {
                unset($entities[$key]);
            }
        }
        unset($conditions['event'], $conditions['plugin']);
    }
    if (!empty($conditions['tags'])) {
        foreach ($entities as $key => $entity) {
            foreach ($conditions['tags'] as $tag) {
                if (in_array($tag, $entity->tags)) {
                    continue 2;
                }
            }
            unset($entities[$key]);
        }
        unset($conditions['tags']);
    }
    return parent::applyConditions($entities, $conditions);
}