0

I would like to define some organic group permissions for a custom entity. The permissions should look like:

  $perms += array(
        "create $type content" => array(
          'title' => t('Create %type_name content', array('%type_name' => $name)),
        ),
        "update own $type content" => array(
          'title' => t('Edit own %type_name content', array('%type_name' => $name)),
        ),
        "update any $type content" => array(
          'title' => t('Edit any %type_name content', array('%type_name' => $name)),
        ),
        "delete own $type content" => array(
          'title' => t('Delete own %type_name content', array('%type_name' => $name)),
        ),
        "delete any $type content" => array(
          'title' => t('Delete any %type_name content', array('%type_name' => $name)),
        ),
      );

How do I do this? I found the function og_get_permissions() to get all set permission, but how to modify this array?

Or may be it should be another way round? You set a normal drupal permission first with:

function custom_example_permission() {
  return array(
    'administer my module' => array(
      'title' => t('Administer my module'),
      'description' => t('Perform administration tasks for my module.'),
    ),
  );
}

And then make it eligible on the permission preferences page of OG? But how?

1

I found the solution here:

/**
 * Implements hook_og_permission().
 */
function custom_permissions_og_permission() {
  $name = "taks";
  return array(
    'update own task content' => array(
      'title' => t('Update own %type_name content', array('%type_name' => $name)),
      'description' => t("Edit own %type_name content.", array('%type_name' => $name)),
      // Determine to which role to limit the permission. For example the
      // "subscribe" can't be assigned only to a non-member, as a member doesn't
      // need it.
      'roles' => array(OG_AUTHENTICATED_ROLE, OG_ADMINISTRATOR_ROLE),
      // Determine to which roles the permissions will be enabled by default.
      'default role' => array(OG_AUTHENTICATED_ROLE, OG_ADMINISTRATOR_ROLE),
    ),
    'update any task content' => array(
      'title' => t('Update any %type_name content', array('%type_name' => $name)),
      'description' => t("Edit any %type_name content.", array('%type_name' => $name)),
      'roles' => array(OG_AUTHENTICATED_ROLE, OG_ADMINISTRATOR_ROLE),
      'default role' => array(OG_ADMINISTRATOR_ROLE),
    ),
    'create new task content' => array(
      'title' => t('Create new %type_name content', array('%type_name' => $name)),
      'description' => t("Create new %type_name content.", array('%type_name' => $name)),
      'roles' => array(OG_AUTHENTICATED_ROLE, OG_ADMINISTRATOR_ROLE),
      'default role' => array(OG_ADMINISTRATOR_ROLE),
    ),
  );
}

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.