function RulesData::applyMetadataAssertions

Property info alter callback for the entity metadata wrapper.

Used for applying the rules metadata assertions.

See also

RulesData::addMetadataAssertions()

1 call to RulesData::applyMetadataAssertions()
RulesData::addSiteMetadata in includes/rules.state.inc
Property info alter callback for the entity metadata wrapper.

File

includes/rules.state.inc, line 593

Class

RulesData
A class holding static methods related to data.

Code

public static function applyMetadataAssertions(EntityMetadataWrapper $wrapper, $property_info) {
    $info = $wrapper->info();
    if (!empty($info['rules assertion'])) {
        $assertion = $info['rules assertion'];
        // In case there are list-wrappers pass through the assertions of the item
        // but make sure we only apply the assertions for the list items for
        // which the conditions are executed.
        if (isset($info['parent']) && $info['parent'] instanceof EntityListWrapper) {
            $assertion = isset($assertion[$info['name']]) ? $assertion[$info['name']] : array();
        }
        // Support specifying multiple bundles, whereas the added properties are
        // the intersection of the bundle properties.
        if (isset($assertion['#info']['bundle'])) {
            $bundles = (array) $assertion['#info']['bundle'];
            foreach ($bundles as $bundle) {
                $properties[] = isset($property_info['bundles'][$bundle]['properties']) ? $property_info['bundles'][$bundle]['properties'] : array();
            }
            // Add the intersection.
            $property_info['properties'] += count($properties) > 1 ? call_user_func_array('array_intersect_key', $properties) : reset($properties);
        }
        // Support adding directly asserted property info.
        if (isset($assertion['#info']['property info'])) {
            $property_info['properties'] += $assertion['#info']['property info'];
        }
        // Pass through any rules assertion of properties to their info, so any
        // derived wrappers apply it.
        foreach (element_children($assertion) as $key) {
            $property_info['properties'][$key]['rules assertion'] = $assertion[$key];
            $property_info['properties'][$key]['property info alter'] = array(
                'RulesData',
                'applyMetadataAssertions',
            );
            // Apply any 'type' and 'bundle' assertion directly to the property
            // info.
            if (isset($assertion[$key]['#info']['type'])) {
                $type = $assertion[$key]['#info']['type'];
                // Support asserting a type in case of generic entity references only.
                if ($property_info['properties'][$key]['type'] == 'entity' && entity_get_info($type)) {
                    $property_info['properties'][$key]['type'] = $type;
                }
            }
            if (isset($assertion[$key]['#info']['bundle'])) {
                $bundle = (array) $assertion[$key]['#info']['bundle'];
                // Add any single bundle directly to the variable info, so the
                // property fits as argument for parameters requiring the bundle.
                if (count($bundle) == 1) {
                    $property_info['properties'][$key]['bundle'] = reset($bundle);
                }
            }
        }
    }
    return $property_info;
}