Created
August 20, 2018 23:02
-
-
Save rvizena/1000423a9cb7e6bfc5fc6da48380b181 to your computer and use it in GitHub Desktop.
D7 email formatter to hide address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = Oog Email Formatter | |
description = Replaces actual email address with the word "email" | |
core = 7.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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