Projet

Général

Profil

Révision 08475715

Ajouté par Assos Assos il y a plus de 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/field_permissions/field_permissions.module
79 79
  return _field_permissions_field_settings_form_alter($form, $form_state, $form_id);
80 80
}
81 81

  
82
/**
83
 * Implements hook_field_permissions_userid_ENTITY_TYPE_alter().
84
 */
85
function field_permissions_field_permissions_userid_field_collection_item_alter(&$uid, $entity) {
86
  $uid = isset($entity->hostEntity()->uid) ? $entity->hostEntity()->uid : $uid;
87
}
88

  
82 89
/**
83 90
 * Implementation of hook_field_access().
84 91
 *
......
124 131
  }
125 132
  // Otherwise, check access by permission.
126 133
  elseif ($field['field_permissions']['type'] == FIELD_PERMISSIONS_CUSTOM) {
134
    // Allow other modules to deny access first.
135
    $result = module_invoke_all('field_permissions_custom_field_access', $op, $field, $entity_type, $entity, $account);
136
    if (in_array(FALSE, $result)) {
137
      return FALSE;
138
    }
139

  
127 140
    if (!isset($entity)) {
128 141
      return field_permissions_empty_entity_access($op, $field['field_name'], $account);
129 142
    }
......
258 271
  // set (for example, if the entity type does not store a uid or does not have
259 272
  // a concept of "ownership"), we need to assume that the provided user
260 273
  // account does not own it.
261
  return isset($entity->uid) && $entity->uid == $account->uid;
274
  $uid = isset($entity->uid) ? $entity->uid : FALSE;
275
  if (method_exists($entity, 'entityType')) {
276
    drupal_alter('field_permissions_userid_' . $entity->entityType(), $uid, $entity);
277
  }
278

  
279
  return $uid === $account->uid;
280
}
281

  
282
/**
283
 * Implements hook_features_pipe_COMPONENT_alter().
284
 *
285
 * Add field permissions to features when exporting a field_base.
286
 */
287
function field_permissions_features_pipe_field_base_alter(&$pipe, $data, $export) {
288
  // Validate if there are field_base components that will be exported for this
289
  // feature.
290
  if (isset($export['features']['field_base'])) {
291
    module_load_include('inc', 'field_permissions', 'field_permissions.admin');
292
    // Iterate through the exported field_base components for this feature and
293
    // add the defined field permissions.
294
    foreach ($export['features']['field_base'] as $field_name) {
295
      $field = field_info_field($field_name);
296
      if (isset($field['field_permissions']['type']) && $field['field_permissions']['type'] == FIELD_PERMISSIONS_CUSTOM) {
297
        $perms = field_permissions_list_field_permissions($field, '');
298
        foreach ($perms as $perm => $info) {
299
          $pipe['user_permission'][] = $perm;
300
        }
301
      }
302
    }
303
  }
304
}
305

  
306
/**
307
 * Implements hook_field_attach_form().
308
 */
309
function field_permissions_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
310
  // Some fields are validated if they are #required even if field's #access
311
  // property is set to false. For example: file/image fields, options fields.
312
  foreach (element_children($form) as $key) {
313
    if (isset($form[$key]['#access']) && !$form[$key]['#access']) {
314
      _field_permissions_make_elements_non_required($form[$key]);
315
    }
316
  }
317
}
318

  
319
/**
320
 * Sets the #required property to FALSE recursively on form elements.
321
 */
322
function _field_permissions_make_elements_non_required(&$elements) {
323
  if (!is_array($elements)) {
324
    return;
325
  }
326
  if (!empty($elements['#required'])) {
327
    $elements['#required'] = FALSE;
328
  }
329
  foreach (element_children($elements) as $key) {
330
    _field_permissions_make_elements_non_required($elements[$key]);
331
  }
332
}
333

  
334
/**
335
 * Implements hook_field_delete_field().
336
 */
337
function field_permissions_field_delete_field($field) {
338
  // Delete any permissions related to the deleted field.
339
  $all_permissions = array_keys(field_permissions_permission());
340
  if (!empty($all_permissions)) {
341
    db_delete('role_permission')
342
      ->condition('module', 'field_permissions')
343
      ->condition('permission', $all_permissions, 'NOT IN')
344
      ->execute();
345
  }
262 346
}

Formats disponibles : Unified diff