function gdpr_consent_agreement_view_entity in General Data Protection Regulation 7
Callback for /admin/config/gdpr/agreements/{gdpr_consent_agreement ID} page.
As we load the entity for display, we're responsible for invoking a number of hooks in their proper order.
See also
1 call to gdpr_consent_agreement_view_entity()
- gdpr_consent_agreement_view_revision in modules/
gdpr_consent/ includes/ gdpr_consent.agreements.inc - Callback for consent agreement revision page.
1 string reference to 'gdpr_consent_agreement_view_entity'
- gdpr_consent_menu in modules/
gdpr_consent/ gdpr_consent.module - Implements hook_menu().
File
- modules/
gdpr_consent/ includes/ gdpr_consent.agreements.inc, line 38 - Pages file for the GDPR Consent module.
Code
function gdpr_consent_agreement_view_entity($entity, $view_mode = 'default') {
// Our entity type, for convenience.
$entity_type = 'gdpr_consent_agreement';
// Start setting up the content.
$entity->content = array(
'#view_mode' => $view_mode,
);
// Build fields content - this is where the Field API really comes in to play.
// The task has very little code here because it all gets taken care of by
// field module.
// field_attach_prepare_view() lets the fields load any data they need
// before viewing.
field_attach_prepare_view($entity_type, array(
$entity->id => $entity,
), $view_mode);
// We call entity_prepare_view() so it can invoke hook_entity_prepare_view()
// for us.
entity_prepare_view($entity_type, array(
$entity->id => $entity,
));
// Now field_attach_view() generates the content for the fields.
$entity->content += field_attach_view($entity_type, $entity, $view_mode);
// OK, Field API done, now we can set up some of our own data.
$entity->content['created'] = array(
'#type' => 'item',
'#title' => t('Created date'),
'#markup' => format_date($entity->created),
);
$entity->content['description'] = array(
'#type' => 'item',
'#title' => t('Description'),
'#markup' => $entity->description,
);
// Now to invoke some hooks. We need the language code for
// hook_entity_view(), so let's get that.
global $language;
$langcode = $language->language;
// And now invoke hook_entity_view().
module_invoke_all('entity_view', $entity, $entity_type, $view_mode, $langcode);
// Now invoke hook_entity_view_alter().
drupal_alter(array(
'gdpr_consent_agreement_view_entity',
'entity_view',
), $entity->content, $entity_type);
// And finally return the content.
return $entity->content;
}