Skip to content
Snippets Groups Projects
Select Git revision
  • 0c5b324809dcb44de8690f7bba21fec607bd67d1
  • 11.x default protected
  • 11.2.x protected
  • 10.6.x protected
  • 10.5.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

system.module

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    crm_core.module 4.30 KiB
    <?php
    
    /**
     * @file
     * Provides basic functionality for a CRM Core.
     */
    
    /**
     * Implements hook_hook_info().
     */
    function crm_core_hook_info() {
      $hooks = array(
        'crm_core_entity_access' => array(
          'group' => 'crm_core',
        ),
      );
    }
    
    /**
     * Return permission names for a given entity type.
     */
    function crm_core_entity_access_permissions($entity_type) {
      $entity_info = entity_get_info($entity_type);
      $labels = $entity_info['permission labels'];
    
      $permissions = array();
    
      // General 'administer' permission.
      $permissions['administer ' . $entity_type . ' entities'] = array(
        'title' => t('Administer @entity_type', array('@entity_type' => $labels['plural'])),
        'description' => t('Allows users to perform any action on @entity_type.', array('@entity_type' => $labels['plural'])),
        'restrict access' => TRUE,
      );
    
      // Generic create and edit permissions.
      $permissions['create ' . $entity_type . ' entities'] = array(
        'title' => t('Create @entity_type of any type', array('@entity_type' => $labels['plural'])),
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['edit own ' . $entity_type . ' entities'] = array(
          'title' => t('Edit own @entity_type of any type', array('@entity_type' => $labels['plural'])),
        );
      }
      $permissions['edit any ' . $entity_type . ' entity'] = array(
        'title' => t('Edit any @entity_type of any type', array('@entity_type' => $labels['singular'])),
        'restrict access' => TRUE,
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['view own ' . $entity_type . ' entities'] = array(
          'title' => t('View own @entity_type of any type', array('@entity_type' => $labels['plural'])),
        );
      }
      $permissions['view any ' . $entity_type . ' entity'] = array(
        'title' => t('View any @entity_type of any type', array('@entity_type' => $labels['singular'])),
        'restrict access' => TRUE,
      );
    
      // Per-bundle create and edit permissions.
      if (!empty($entity_info['entity keys']['bundle'])) {
        foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
          $permissions += crm_core_bundle_access_permissions($bundle_name, $bundle_info, $entity_type, $entity_info);
        }
    
      }
    
      return $permissions;
    }
    
    /**
     * Define per-bundle permissions.
     */
    function crm_core_bundle_access_permissions($bundle_name, $bundle_info, $entity_type, $entity_info = array()) {
      $labels = $entity_info['permission labels'];
    
      $permissions['create ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
        'title' => t('Create %bundle @entity_type', array('@entity_type' => $labels['plural'], '%bundle' => $bundle_info['label'])),
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['edit own ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
          'title' => t('Edit own %bundle @entity_type', array('@entity_type' => $labels['plural'], '%bundle' => $bundle_info['label'])),
        );
      }
      $permissions['edit any ' . $entity_type . ' entity of bundle ' . $bundle_name] = array(
        'title' => t('Edit any %bundle @entity_type', array('@entity_type' => $labels['singular'], '%bundle' => $bundle_info['label'])),
        'restrict access' => TRUE,
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['delete own ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
          'title' => t('Delete own %bundle @entity_type', array('@entity_type' => $labels['plural'], '%bundle' => $bundle_info['label'])),
        );
      }
      $permissions['delete any ' . $entity_type . ' entity of bundle ' . $bundle_name] = array(
        'title' => t('Delete any %bundle @entity_type', array('@entity_type' => $labels['singular'], '%bundle' => $bundle_info['label'])),
        'restrict access' => TRUE,
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['view own ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
          'title' => t('View own %bundle @entity_type', array('@entity_type' => $labels['plural'], '%bundle' => $bundle_info['label'])),
        );
      }
      $permissions['view any ' . $entity_type . ' entity of bundle ' . $bundle_name] = array(
        'title' => t('View any %bundle @entity_type', array('@entity_type' => $labels['singular'], '%bundle' => $bundle_info['label'])),
        'restrict access' => TRUE,
      );
    
      return $permissions;
    }