commerce_uuid.module in Commerce UUID 7
Adds universally unique identifiers support to Drupal Commerce.
File
commerce_uuid.moduleView source
<?php
/**
* @file
* Adds universally unique identifiers support to Drupal Commerce.
*/
/**
* Implements hook_entity_info_alter().
*/
function commerce_uuid_entity_info_alter(&$entity_info) {
if (isset($entity_info['commerce_customer_profile'])) {
$entity_info['commerce_customer_profile']['uuid'] = TRUE;
$entity_info['commerce_customer_profile']['entity keys']['uuid'] = 'uuid';
$entity_info['commerce_customer_profile']['entity keys']['revision uuid'] = 'vuuid';
}
if (isset($entity_info['commerce_line_item'])) {
$entity_info['commerce_line_item']['uuid'] = TRUE;
$entity_info['commerce_line_item']['entity keys']['uuid'] = 'uuid';
}
if (isset($entity_info['commerce_order'])) {
$entity_info['commerce_order']['uuid'] = TRUE;
$entity_info['commerce_order']['entity keys']['uuid'] = 'uuid';
$entity_info['commerce_order']['entity keys']['revision uuid'] = 'vuuid';
}
if (isset($entity_info['commerce_payment_transaction'])) {
$entity_info['commerce_payment_transaction']['uuid'] = TRUE;
$entity_info['commerce_payment_transaction']['entity keys']['uuid'] = 'uuid';
$entity_info['commerce_payment_transaction']['entity keys']['revision uuid'] = 'vuuid';
}
if (isset($entity_info['commerce_product'])) {
$entity_info['commerce_product']['uuid'] = TRUE;
$entity_info['commerce_product']['entity keys']['uuid'] = 'uuid';
$entity_info['commerce_product']['entity keys']['revision uuid'] = 'vuuid';
}
}
/**
* Implements hook_entity_uuid_load().
*/
function commerce_uuid_entity_uuid_load(&$entities, $entity_type) {
if ($entity_type == 'commerce_customer_profile') {
entity_property_id_to_uuid($entities, 'user', 'uid');
}
if ($entity_type == 'commerce_line_item') {
entity_property_id_to_uuid($entities, 'commerce_order', array(
'order_id',
));
}
if ($entity_type == 'commerce_order') {
entity_property_id_to_uuid($entities, 'user', array(
'uid',
'revision_uid',
));
}
if ($entity_type == 'commerce_payment_transaction') {
entity_property_id_to_uuid($entities, 'user', 'uid');
entity_property_id_to_uuid($entities, 'commerce_order', 'order_id');
}
if ($entity_type == 'commerce_product') {
entity_property_id_to_uuid($entities, 'user', 'uid');
}
}
/**
* Implements hook_entity_uuid_presave().
*/
function commerce_uuid_entity_uuid_presave(&$entity, $entity_type) {
if ($entity_type == 'commerce_customer_profile') {
entity_property_uuid_to_id($entity, 'user', 'uid');
}
if ($entity_type == 'commerce_line_item') {
entity_property_uuid_to_id($entity, 'commerce_order', array(
'order_id',
));
}
if ($entity_type == 'commerce_order') {
entity_property_uuid_to_id($entity, 'user', array(
'uid',
'revision_uid',
));
}
if ($entity_type == 'commerce_payment_transaction') {
entity_property_uuid_to_id($entity, 'user', 'uid');
entity_property_uuid_to_id($entity, 'commerce_order', 'order_id');
}
if ($entity_type == 'commerce_product') {
entity_property_uuid_to_id($entity, 'user', 'uid');
}
}
/**
* Implements hook_field_uuid_load() for commerce_customer.module.
*/
function commerce_customer_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
entity_property_id_to_uuid($items, 'commerce_customer_profile', 'profile_id');
}
/**
* Implements hook_field_uuid_presave() for commerce_customer.module.
*/
function commerce_customer_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
entity_property_uuid_to_id($items, 'commerce_customer_profile', 'profile_id');
}
/**
* Implements hook_field_uuid_load() for commerce_line_item.module.
*/
function commerce_line_item_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
entity_property_id_to_uuid($items, 'commerce_line_item', 'line_item_id');
}
/**
* Implements hook_field_uuid_presave() for commerce_line_item.module.
*/
function commerce_line_item_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
entity_property_uuid_to_id($items, 'commerce_line_item', 'line_item_id');
}
/**
* Implements hook_field_uuid_load() for commerce_product_reference.module.
*/
function commerce_product_reference_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) {
entity_property_id_to_uuid($items, 'commerce_product', 'product_id');
}
/**
* Implements hook_field_uuid_presave() for commerce_product_reference.module.
*/
function commerce_product_reference_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
entity_property_uuid_to_id($items, 'commerce_product', 'product_id');
}
/**
* Implements hook_commerce_customer_profile_presave().
*/
function commerce_uuid_commerce_customer_profile_presave($profile) {
$info = entity_get_info('commerce_customer_profile');
if (empty($profile->profile_id) && !empty($info['uuid']) && !empty($info['entity keys']['uuid'])) {
$uuid_key = $info['entity keys']['uuid'];
$profile->{$uuid_key} = '';
if (empty($profile->revision_id) && !empty($info['entity keys']['revision uuid'])) {
$vuuid_key = $info['entity keys']['revision uuid'];
$profile->{$vuuid_key} = '';
}
}
}
Functions
Name![]() |
Description |
---|---|
commerce_customer_field_uuid_load | Implements hook_field_uuid_load() for commerce_customer.module. |
commerce_customer_field_uuid_presave | Implements hook_field_uuid_presave() for commerce_customer.module. |
commerce_line_item_field_uuid_load | Implements hook_field_uuid_load() for commerce_line_item.module. |
commerce_line_item_field_uuid_presave | Implements hook_field_uuid_presave() for commerce_line_item.module. |
commerce_product_reference_field_uuid_load | Implements hook_field_uuid_load() for commerce_product_reference.module. |
commerce_product_reference_field_uuid_presave | Implements hook_field_uuid_presave() for commerce_product_reference.module. |
commerce_uuid_commerce_customer_profile_presave | Implements hook_commerce_customer_profile_presave(). |
commerce_uuid_entity_info_alter | Implements hook_entity_info_alter(). |
commerce_uuid_entity_uuid_load | Implements hook_entity_uuid_load(). |
commerce_uuid_entity_uuid_presave | Implements hook_entity_uuid_presave(). |