You are here

function pmpapi_permissions_attach_perm_elements in Public Media Platform API Integration 7

Attaches any applicable permission elements to a given (entity CRUD) form.

$form array An entity CRUD form array.

$entity_type string The type of entity to which the permissions could be added.

$bundle_name string The bundle name of the entity to which the permissions could be added.

3 calls to pmpapi_permissions_attach_perm_elements()
pmpapi_permissions_form_file_entity_add_upload_alter in pmpapi_permissions/pmpapi_permissions.module
Implements hook_form_FORM_ID_alter() for file_entity_add_upload().
pmpapi_permissions_form_file_entity_edit_alter in pmpapi_permissions/pmpapi_permissions.module
Implements hook_form_FORM_ID_alter() for file_entity_edit().
pmpapi_permissions_form_node_form_alter in pmpapi_permissions/pmpapi_permissions.module
Implements hook_form_BASE_FORM_ID_alter().

File

pmpapi_permissions/pmpapi_permissions.module, line 166

Code

function pmpapi_permissions_attach_perm_elements(&$form, $entity_type, $bundle_name) {
  $uname = $entity_type . '__' . $bundle_name;
  if (variable_get('pmpapi_push_' . $uname . '_profile')) {
    $form['pmpapi_permissions'] = array(
      '#type' => 'fieldset',
      '#title' => t('PMP API permission settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    if (!empty($form['additional_settings'])) {
      $form['pmpapi_permissions']['#group'] = 'additional_settings';
    }
    $guid = pmpapi_permissions_extract_guid_from_form($form, $entity_type);
    $permissions = $guid ? pmpapi_permissions_fetch_permissions($guid) : array();
    $permission = !empty($permissions) ? $permissions[0] : NULL;
    if ($guid) {

      // GUID means a pre-existing doc
      if ($permission) {

        // Grab group from permission object
        $default_group_value = end(explode('/', $permission->href));
      }
      else {

        // Assume no permission means group = 'All'
        $default_group_value = 0;
      }
    }
    else {

      // New node/doc; we are on the add form, so grab default value (if it
      // exists).
      $default_group_value = variable_get('pmpapi_permissions_default_group_' . $uname, 0);
    }
    $form['pmpapi_permissions']['pmpapi_permissions_group'] = array(
      '#title' => t('Which PMP users can access these files (via the PMP API)?'),
      '#type' => 'select',
      '#multiple' => FALSE,
      '#default_value' => $default_group_value,
      '#required' => TRUE,
      '#options' => pmpapi_permissions_get_group_options(),
      '#disabled' => !user_access('apply PMP permissions'),
    );
    if (isset($form['actions']['submit']['#submit'])) {
      array_unshift($form['actions']['submit']['#submit'], 'pmpapi_permissions_set_' . $entity_type . '_permissions');
    }
    elseif (isset($form['#submit'])) {

      // Forms such as the multi-step at file/add might have submit handlers elsewhere
      array_unshift($form['#submit'], 'pmpapi_permissions_set_' . $entity_type . '_permissions');
    }
  }
}