Created
January 25, 2017 09:49
-
-
Save martsie/205cc8f13c7dfc1b72d3787e4334389f to your computer and use it in GitHub Desktop.
Entity Metadata Wrapper hooks for Drupal 7 user data abstraction
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 | |
/** | |
* Implements hook_entity_property_info_alter(). | |
*/ | |
function my_custom_module_entity_property_info_alter(&$info) { | |
$properties = &$info['user']['properties']; | |
$properties['employee_number'] = array( | |
'label' => t("Employee number"), | |
'description' => t("The employee number of this user."), | |
'type' => 'integer', | |
'getter callback' => 'my_custom_module_get_employee_number', | |
'setter callback' => 'my_custom_module_set_employee_number', | |
); | |
} | |
/** | |
* Entity API getter for user account employee number. | |
* | |
* @see my_custom_module_entity_property_info_alter(). | |
*/ | |
function my_custom_module_get_employee_number($account, array $options, $name, $entity_type) { | |
$employee_details = new EmployeeDetails($account); | |
return $employee_details->getEmployeeNumber(); | |
} | |
/** | |
* Entity API setter for user account employee number. | |
* | |
* @see my_custom_module_entity_property_info_alter(). | |
*/ | |
function my_custom_module_set_employee_number($account, $name, $value) { | |
$employee_details = new EmployeeDetails($account); | |
$employee_details->setEmployeeNumber($value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment