Skip to content

Instantly share code, notes, and snippets.

@e0ipso
Created March 11, 2017 10:44
Show Gist options
  • Save e0ipso/5a3a9511c0f1af944aca988175cc89c1 to your computer and use it in GitHub Desktop.
Save e0ipso/5a3a9511c0f1af944aca988175cc89c1 to your computer and use it in GitHub Desktop.
Allow setting the UUID from the front-end
<?php
/**
* Implements hook_entity_property_info_alter().
*/
function mymodule_entity_property_info_alter(&$info) {
// Add the uuid setter if not present.
foreach (entity_get_info() as $entity_type => $entity_info) {
if (
!empty($entity_info['uuid'])
&& !empty($entity_info['entity keys']['uuid'])
&& !empty($info[$entity_type]['properties'][$entity_info['entity keys']['uuid']])
) {
// This entity type supports a UUID.
$uuid_info = &$info[$entity_type]['properties'][$entity_info['entity keys']['uuid']];
$uuid_info['setter callback'] = 'entity_property_verbatim_set';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment