Skip to content

Instantly share code, notes, and snippets.

@martsie
Last active January 25, 2017 09:47
Show Gist options
  • Save martsie/fd5f4e6e52d451c39b5c5d4b35a4da8e to your computer and use it in GitHub Desktop.
Save martsie/fd5f4e6e52d451c39b5c5d4b35a4da8e to your computer and use it in GitHub Desktop.
Nicer OOP implementation of storing and accessing structured data in Drupal 7 user object
<?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);
$salary = $employee->getEmployeeSalary();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment