0

I am developing an extension. I want to provide permissions using drupal.

enter image description here

I am using following hook for creating a permission

hook_civicrm_permission(&$permissions);

But, how to do that (means can view or edit some custom data)? Please suggest some similar extensions.

1

There is a example and information on the hook here. Throw the hook into your custom module and it should work. The below example includes a version check that you likely won't need.

function civimonitor_civicrm_permission(&$permissions) {
  $version = CRM_Utils_System::version();
  if (version_compare($version, '4.6.1') >= 0) {
    $permissions += array(
      'access CiviMonitor' => array(
        ts('Access CiviMonitor', array('domain' => 'com.aghstrategies.civimonitor')),
        ts('Grants the necessary API permissions for a monitoring user without Administer CiviCRM', array('domain' => 'com.aghstrategies.civimonitor')),
      ),
    );
  }
  else {
    $permissions += array(
      'access CiviMonitor' => ts('Access CiviMonitor', array('domain' => 'com.aghstrategies.civimonitor')),
    );
  }
}
  • In my scenario, only admin can see but authenticate user should not access these extension pages. How to do that? – deepak Apr 5 at 9:49
  • Think this is what you are after: docs.civicrm.org/dev/en/latest/hooks/… . I haven't had to implemented it before, but that seems like the correct route to follow. Imagine someone else can probably feedback with more detail but best path could be to look at how existing extensions function. – EagleUK Apr 5 at 9:55
  • I am not understanding. Is there any simple extension or snippets to understand permission hooks? – deepak Apr 5 at 10:17
  • @deepak Have you worked much with Drupal permissions before? If not probably a good place to start then move on to doing what you need to do with civi perms :). This will give you a basic look at a drupal module that uses permissions for page access: drupal.org/docs/7/creating-custom-modules/… – EagleUK Apr 5 at 10:33
  • Hello@EagleUK I created a page(using civix tool) but that page must access only a site admin and does not access to other authenticated users. – deepak Apr 5 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.