Skip to content

Instantly share code, notes, and snippets.

@rvizena
Created August 20, 2018 23:02
Show Gist options
  • Save rvizena/1000423a9cb7e6bfc5fc6da48380b181 to your computer and use it in GitHub Desktop.
Save rvizena/1000423a9cb7e6bfc5fc6da48380b181 to your computer and use it in GitHub Desktop.
D7 email formatter to hide address
name = Oog Email Formatter
description = Replaces actual email address with the word "email"
core = 7.x
<?php
/**
* Implements hook_field_formatter_info().
*
*/
function oog_email_formatter_field_formatter_info() {
// Add a setting to a formatter type.
$formats = array(
'email_custom' => array(
'label' => t('Email Custom'),
'description' => t('Display the email address as custom format.'),
'field types' => array('email'),
),
);
return $formats;
}
/**
* Implements hook_field_formatter_view().
*/
function oog_email_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'email_custom':
foreach ($items as $delta => $item) {
$output = l("Email", 'mailto:' . $item['email']);
$element[$delta] = array('#markup' => $output);
}
break;
}
return $element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment