Created
October 13, 2016 12:48
-
-
Save clrockwell/072cd9eae7153e290f1ba884d89a27aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Two hooks are necessary for adding an extra field to an entity display | |
*/ | |
/** | |
* Implements hook_entity_view(). | |
* Define the content that should be shown | |
*/ | |
function hook_entity_view($entity, $type, $view_mode, $langcode) { | |
if ($entity->type == 'event') { | |
$gateway = sms_gateways('gateway', 'twilio'); | |
$number = $gateway['configuration']['sms_twilio_number']; | |
$field = [ | |
'#title' => t('SMS Phone Number'), | |
'#type' => 'item', | |
'#id' => 'sms-number', | |
'#markup' => $number, | |
]; | |
$entity->content['sms_number'] = $field; | |
} | |
} | |
/** | |
* Implements hook_field_extra_fields(). | |
* Register the field so it can be managed in "Manage Display" | |
*/ | |
function hook_field_extra_fields() { | |
// Often you'll want to loop over entity_get_info() | |
// unless you know exactly what entity_type and bundle you're targeting | |
// This array is $extra[ENTITY_TYPE][BUNDLE_TYPE][VIEW_MODE][FIELD] | |
$extra['event']['event']['display']['sms_number'] = [ | |
'label' => t('SMS Phone Number'), | |
'description' => t('The number to text SMS Event Code to'), | |
'weight' => 0, | |
]; | |
return $extra; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment