function _taxonomy_access_entity_fields in Taxonomy Access Control 7
Helper function to extract the taxonomy fields from an entity.
Parameters
object $entity: The entity object.
Return value
array An associative array of field information, containing:
- field_list: A flat array of all this entity's taxonomy fields, with the format $field_name => $field_name.
- langcodes: A flat array of all langcodes in this entity's fields, with the format $langcode => $langcode.
- data: An associative array of non-empty fields:
- $field_name: An associative array keyed by langcode.
- $langcode: Array of field values for this field name and langcode.
- $field_name: An associative array keyed by langcode.
See also
http://drupal.org/node/1220168
Related topics
1 call to _taxonomy_access_entity_fields()
- _taxonomy_access_field_validate in ./
taxonomy_access.create.inc - Validates form submissions of taxonomy fields for create grants.
File
- ./
taxonomy_access.create.inc, line 700 - Implements the Add Tag (create) grant on editing forms.
Code
function _taxonomy_access_entity_fields($entity_type, $entity, $bundle) {
// Maintain separate lists of field names and langcodes for quick comparison.
$fields = array();
$fields['field_list'] = array();
$fields['langcodes'] = array();
$fields['data'] = array();
// If there is no entity, return the empty structure.
if (!$entity) {
return $fields;
}
// Get a list of possible fields for the bundle.
// The bundle does not contain the field type (see #122016), so our only use
// for it is the field names.
$possible = array_keys(field_info_instances($entity_type, $bundle));
// Sort through the entity for relevant field data.
foreach ($entity as $field_name => $field) {
// Only proceed if this element is a valid field for the bundle.
if (in_array($field_name, $possible, TRUE)) {
// Check whether each entity field is a taxonomy field.
$info = field_info_field($field_name);
if ($info['type'] == 'taxonomy_term_reference') {
foreach ($field as $langcode => $values) {
// Add non-empty fields to the lists.
if (!empty($values)) {
$fields['langcodes'][$langcode] = $langcode;
$fields['field_list'][$field_name] = $field_name;
$fields['data'][$field_name][$langcode] = $values;
}
unset($values);
}
}
}
unset($info);
unset($field);
}
unset($entity);
return $fields;
}