function email_contact_mail_page in Email Contact 7
The contact form page.
1 call to email_contact_mail_page()
- email_contact_field_formatter_view in ./
email_contact.module - Implements hook_field_formatter_view().
1 string reference to 'email_contact_mail_page'
- email_contact_menu in ./
email_contact.module - Implements hook_menu().
File
- ./
email_contact.module, line 273 - File name: email_contact.module.
Code
function email_contact_mail_page($object_type, $object_id, $field_name, $widget_settings = array()) {
global $user;
if (!is_numeric($object_id)) {
return MENU_NOT_FOUND;
}
// Verify this is an email field.
$field_info = field_info_field($field_name);
if (!isset($field_info) || $field_info['type'] != 'email') {
return MENU_NOT_FOUND;
}
// Check that the entity exists.
$objects = entity_load($object_type, array(
$object_id,
));
if (!isset($objects[$object_id])) {
return MENU_NOT_FOUND;
}
$object = $objects[$object_id];
// Check that the entity has the email field.
if (!isset($object->{$field_name})) {
return MENU_NOT_FOUND;
}
// Check if the current user has access to the entity and to the field.
if (!email_contact_mail_page_access($object_type, $object, $field_info)) {
return MENU_ACCESS_DENIED;
}
// Use the first email address as receiver.
$field = array_pop($object->{$field_name});
$emails = array();
foreach ($field as $delta => $item) {
if (!empty($item['email']) && strpos($item['email'], '@') !== FALSE) {
$emails[] = $item['email'];
}
}
// Verify that the email address is not empty.
if (empty($emails)) {
return MENU_NOT_FOUND;
}
$entity_info = entity_extract_ids($object_type, $object);
$settings = field_info_instance($object_type, $field_name, $entity_info[2]);
$found = FALSE;
foreach ($settings['display'] as $display_name => $display_data) {
if (isset($display_data['type']) && ($display_data['type'] === 'email_contact_link' || $display_data['type'] === 'email_contact_inline')) {
if (empty($widget_settings)) {
$widget_settings = $display_data['settings'];
}
$found = TRUE;
break;
}
}
if (!$found) {
return MENU_NOT_FOUND;
}
if ($GLOBALS['user']->uid != 1 && !flood_is_allowed('email', variable_get('email_hourly_threshold', 3))) {
return t("You cannot send more than %number messages per hour. Please try again later.", array(
'%number' => variable_get('email_hourly_threshold', 3),
));
}
return drupal_get_form('email_contact_mail_page_form', $object_type, $object_id, $field_name, $emails, $widget_settings);
}