function entity_embed_filter_parse_from_fields in Entity Embed 7.2
Same name and namespace in other branches
- 7 includes/entity_embed.file_usage.inc \entity_embed_filter_parse_from_fields()
Parse file references from an entity's text fields.
Parameters
$entity: The entity whose fields are being parsed.
$entity_type: The type of the entity whose fields are being parsed.
Return value
An array of file IDs corresponding to the files referenced in the fields.
1 call to entity_embed_filter_parse_from_fields()
- entity_embed_entity_field_count_files in includes/
entity_embed.file_usage.inc - Retrieve a count of all of the files referenced by an entity.
File
- includes/
entity_embed.file_usage.inc, line 152 - Tracks usage of embedded files.
Code
function entity_embed_filter_parse_from_fields($entity_type, $entity) {
$fids = array();
// Loop through the individual field items for all of the field instances
// attached to the entity which support text processing and check if any of
// them contain references to embedded files.
foreach (entity_embed_filter_fields_with_text_filtering($entity_type, $entity) as $field_name) {
if ($field_items = field_get_items($entity_type, $entity, $field_name)) {
foreach ($field_items as $field_item) {
$text = $field_item['value'];
if (stristr($text, 'data-entity-type="file"') !== FALSE) {
$dom = entity_embed_dom_load_html($text);
$xpath = new \DOMXPath($dom);
foreach ($xpath
->query('//*[@data-entity-type="file" and (@data-entity-uuid or @data-entity-id)]') as $node) {
$uuid = $node
->getAttribute('data-entity-uuid');
$id = $node
->getAttribute('data-entity-id');
if (!empty($uuid) && module_exists('uuid')) {
$ids = entity_get_id_by_uuid('file', array(
$uuid,
));
$fid = reset($ids);
}
else {
$fid = $id;
}
$fids[] = $fid;
}
}
}
}
}
return $fids;
}