function mandrill_activity_page in Mandrill 7
Same name and namespace in other branches
- 7.2 modules/mandrill_activity/mandrill_activity.module \mandrill_activity_page()
Content for the Mandrill log tab on entity instance pages.
@object $entity Entity to load activity for.
Parameters
MandrillActivityEntity $mandrill_activity_entity: Loaded MandrillActivityEntity object.
Return value
array Render array.
1 string reference to 'mandrill_activity_page'
- mandrill_activity_menu in modules/
mandrill_activity/ mandrill_activity.module - Implements hook_menu().
File
- modules/
mandrill_activity/ mandrill_activity.module, line 105 - Main module functions for mandrill_activity.
Code
function mandrill_activity_page($entity, MandrillActivityEntity $mandrill_activity_entity) {
$entity_wrapper = entity_metadata_wrapper($mandrill_activity_entity->entity_type, $entity);
$email_property = $mandrill_activity_entity->email_property;
$email_property_array = explode(':', $email_property);
$parent = $entity_wrapper;
foreach ($email_property_array as $drupal_field) {
if ($parent instanceof EntityListWrapper) {
$child_wrapper = $parent
->get(0)->{$drupal_field};
}
else {
$child_wrapper = $parent->{$drupal_field};
}
$parent = $child_wrapper;
}
$email = $parent
->value();
// Validate email address.
if (!valid_email_address($email)) {
return array(
'error_notice' => array(
'#markup' => t('%email does not contain a valid email address. Unable to lookup Mandrill activity history without a valid email.', array(
'%email' => $email_property,
)),
),
);
}
$header = array(
t('Subject'),
t('Timestamp'),
t('State'),
t('Opens'),
t('Clicks'),
t('Tags'),
);
$rows = array();
// Loop through all activities, creating rows for each.
$activity = mandrill_activity_get_activity($email);
foreach ($activity as $sent_email) {
$rows[] = array(
$sent_email['subject'],
format_date($sent_email['ts'], 'short'),
$sent_email['state'],
$sent_email['opens'],
$sent_email['clicks'],
implode(', ', $sent_email['tags']),
);
}
$display['mandrill_activity'] = array(
'message' => array(
'#markup' => t('The 100 most recent Emails sent to %email via Mandrill.', array(
'%email' => $email,
)),
),
'activity' => array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
),
);
return $display;
}