User data wrapper

Categories

Component ID

2549517

Component name

User data wrapper

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

315

Component created

Component changed

Component body

This is a module that allows you to use the $account->data in a structured way. The use case for this module would be if you need to store small amounts of data against a user that needs no UI, then this would be a good fit. Do not user $account->data as a replacement for fields.

You can then use entity meta wrappers to get or set your defined data as properties.

You define properties using a user_data_info hook:

function hook_user_data_info() {
  return array(
    'property_key' => array(
      'label' => t('Property label'),
      'type' => 'text',
    ),
  );
}

Note: the type expects the values defined in entity_property_info definition, see http://www.drupalcontrib.org/api/drupal/contributions!entity!entity.api....

and then you can use your data like this:

$wrapper = entity_metadata_wrapper('user', $user);
$wrapper->property_key->set('text string');
or
$wrapper->property_key->value();