You are here

function pmpapi_permissions_set_file_permissions in Public Media Platform API Integration 7

Creates a PMP permission object from fields, then attaches it to the file object in the form.

$form array An entity CRUD form array.

$form_state array The current state of the form

File

pmpapi_permissions/pmpapi_permissions.module, line 254

Code

function pmpapi_permissions_set_file_permissions($form, &$form_state) {
  $entity_type = 'file';
  $group = !empty($form_state['values']['pmpapi_permissions_group']) ? $form_state['values']['pmpapi_permissions_group'] : NULL;
  $permission = pmp_permissions_create_permission($group);
  $permissions = $permission !== NULL ? array(
    $permission,
  ) : NULL;

  // check for multi-step file entity form
  if (isset($form_state['build_info']['form_id']) && $form_state['build_info']['form_id'] == 'file_entity_add_upload' && $form_state['step'] == 4) {
    $form_state['values']['pmpapi_permissions'] = $permissions;
    $form_state['values']['pmpapi_permissions_added'] = TRUE;
  }
  else {
    $form_state[$entity_type]->pmpapi_permissions = $permissions;
    $form_state[$entity_type]->pmpapi_permissions_added = TRUE;
  }
}