You are here

function pmpapi_permissions_entity_presave in Public Media Platform API Integration 7

Implements hook_entity_presave().

File

pmpapi_permissions/pmpapi_permissions.module, line 340

Code

function pmpapi_permissions_entity_presave($entity, $type) {
  $wrapper = entity_metadata_wrapper($type, $entity);
  $bundle = $wrapper
    ->getBundle();
  $uname = $type . '__' . $bundle;
  $default_group = variable_get('pmpapi_permissions_default_group_' . $uname, 0);

  // If entity has not had a permission added, but DOES have a default whitelist
  // group, add it to the entity. Most obvious use-case: an entity that is added
  // programmatically (i.e., no form used)
  if (empty($entity->pmpapi_permissions_added) && $default_group) {
    $permission = pmp_permissions_create_permission($default_group);
    $entity->pmpapi_permissions = array(
      $permission,
    );
  }
}