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_init(). | |
* | |
* Runs every time a page is requested on the site. | |
*/ | |
function my_custom_module_init() { | |
if (user_access('my custom permission')) { | |
drupal_set_message(t('User has my custom permission')); | |
} |
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_permission(). | |
* | |
* Defines a new permission called 'my custom permission'. | |
*/ | |
function my_custom_module_permission() { | |
return array( | |
'my custom permission' => array( | |
'title' => t('My custom permission'), |
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
drush sql-query "UPDATE system SET schema_version = 7001 WHERE name = 'my_custom_module';" |
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."), |
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 | |
global $user; | |
$account = entity_metadata_wrapper('user', $user); | |
$account->employee_number->set(60000); | |
entity_save('user', $account); | |
$employee_number = $account->employee_number->value(); |
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 | |
class EmployeeDetails { | |
/** | |
* The associated user account. | |
*/ | |
protected $account; | |
/** | |
* The key for accessing data. | |
*/ |
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 | |
// Set the employee salary of a user. | |
$account = user_load(1); | |
$employee_details = new EmployeeDetails($account); | |
$employee_details->setEmployeeSalary(65000); | |
user_save($account); | |
// Retrieve the employee salary for a given user. | |
$account = user_load(1); | |
$employee_details = new EmployeeDetails($account); |
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 | |
$user->data['employee'] = array( | |
'employee_number' => 123456, | |
'employee_details' => array( | |
'salary' => 65000, | |
'access_level' => 'A', | |
'start_date' => 1425439660, | |
), | |
); | |
user_save($user); |
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 | |
// Add some data to the current user. | |
global $user; | |
$user->data['foo'] = 'bar'; | |
user_save($user); | |
// Access some data from the current user. | |
global $user; | |
$user_data = $user->data['foo']; |
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
QUnit.module 'Waiter class' | |
test 'Waiter waits for 1 second twice', (assert) -> | |
done1 = do assert.async | |
done2 = do assert.async | |
assert.expect 2 | |
waiter = new Waiter() | |