function _microdata_prepare_mapping in Microdata 7
Helper function to prepare a microdata mapping for use.
Because microdata requires attributes to be placed differently depending on the value type, microdata needs to know what the value type of each field is. Microdata module piggybacks on Entity API and maps Entity API values to corresponding microdata value types. This function processes the whole mapping through the conversion.
Parameters
array $mapping: The mapping to prepare.
string $entity_type: The entity type.
string $bundle_type: The bundle type.
1 call to _microdata_prepare_mapping()
- microdata_get_mapping in ./
microdata.module - Returns the mapping for fields and properties of a particular bundle.
File
- ./
microdata.module, line 1016
Code
function _microdata_prepare_mapping(&$mapping, $entity_type, $bundle_type) {
$property_info = entity_get_property_info($entity_type);
// We have to check that the $bundle_type property exists here for two
// reasons.
// - Panels seems to inject a 'panel' bundle type into the node entity array.
// - Deleted or otherwise missing file bundles can still show up in the
// $entity['bundles'] array (possibly when using File Entity module).
if (isset($property_info['bundles']) && isset($property_info['bundles'][$bundle_type])) {
$bundle_properties = $property_info['bundles'][$bundle_type]['properties'];
}
// @todo Figure out if any of this can be refactored using proper Entity API
// integration above.
$fields = field_info_fields();
_microdata_mapping_add_defaults($mapping, $entity_type, $bundle_type, $fields);
foreach ($mapping as $field_name => &$field_mapping) {
// If this is an attribute value (which start with #) or is a pseudo-field
// (like title), then continue.
if ($field_name[0] === '#' || !isset($bundle_properties[$field_name])) {
continue;
}
$field_info = $bundle_properties[$field_name];
// If this field type is registered with the Microdata system, convert the
// Entity API property_type to a value type.
if (microdata_enabled($field_info)) {
$field_mapping['#value_type'] = microdata_get_value_type($bundle_properties[$field_name]['type']);
}
// Iterate through the properties within the field. If the mapping's key
// matches a registered property, get the value type.
$properties = _microdata_get_field_properties($entity_type, $bundle_type, $field_name);
foreach ($field_mapping as $subfield_name => &$subfield_mapping) {
if (isset($properties[$subfield_name])) {
$subfield_mapping['#value_type'] = microdata_get_value_type($properties[$subfield_name]['type']);
}
}
}
// Set the main entity's value type.
$mapping['#value_type'] = 'item';
}