function entity_embed_get_entity_field_formatters in Entity Embed 7.3
Helper function to get all the field formatters that we can use to display entity types.
Parameters
$entity_type: The type of entity, i.e. 'node', 'user'.
$entity: (optional) The entity to be rendered. This is used to perform special checks/processing for unruly modules.
Return value
array
4 calls to entity_embed_get_entity_field_formatters()
- EntityEmbedTestBase::assertAvailableDisplayPlugins in ./
entity_embed.test - entity_embed_ctools_export_ui_form in plugins/
export_ui/ entity_embed_ctools_export_ui_form.inc - Define the preset add/edit form.
- entity_embed_dialog_form in ./
entity_embed.admin.inc - Form constructor for the entity embed dialog form.
- entity_embed_dialog_form_validate in ./
entity_embed.admin.inc - Form validation handler for entity_embed_dialog_form().
File
- includes/
entity_embed.display.inc, line 223 - Display functions.
Code
function entity_embed_get_entity_field_formatters($entity_type, $entity = NULL) {
$formatters = field_info_formatter_types();
$field_types = entity_embed_get_entity_field_types($entity_type);
$entity_formatters = array();
foreach ($formatters as $formatter => $info) {
// Files require special handling.
if ($entity_type == 'file') {
// Files behave differently depending on whether the File Entity module is
// available.
if (module_exists('file_entity')) {
// With the File Entity module enabled, file entities require some
// special handling. Unlike standard field formatters which specify a
// list of compatible entity types and will work with any entity as long
// as it is the correct type, file formatters may only support files
// with specific MIME types.
if (isset($entity) && isset($info['file formatter']['mime types']) && isset($entity->filemime)) {
if (!file_entity_match_mimetypes($info['file formatter']['mime types'], $entity->filemime)) {
// Skip the incompatible formatter.
continue;
}
}
}
else {
// The 'Rendered entity' formatter can not be used for files unless the
// File Entity module is available.
if ($formatter == 'entityreference_entity_view') {
// Skip the incompatible formatter.
continue;
}
}
}
// With the File Image Formatters module enabled, image field formatters
// will appear twice.
if ($info['module'] == 'file_image_formatters' && module_exists('file_image_formatters')) {
// Skip the duplicate formatter.
continue;
}
foreach ($info['field types'] as $field_type) {
if (in_array($field_type, $field_types)) {
$entity_formatters[$info['module'] . ':' . $formatter] = $info['label'];
break;
}
}
}
return $entity_formatters;
}