how to edit access level ?

A entity with 'Friends' access level can be visible by friends (a user that I add as friend) , I want to edit it to 'Friendof' access level , so only my 'friendof' ( a user that add me as friend) can see my post , any suggestion ?

Can  'inverse_relationship' be used for this case ? what's file i must edit ?

  • I created a gist here: https://gist.github.com/hypeJunction/e6cc1f5efc00ca06671acba0f142d942

    <?php
    /**
     * Define a new access level to allow owners to save content visible to those who added them as a friend,
     * as oppose to Friends access level, which shows content to users that have been added as friends by the owner
     *
     * Note that Elgg friendships are not reciprocal by default
     */
    define('ACCESS_FRIENDS_OF', -2); // make sure this is not used by other plugins
    
    elgg_register_event_handler('init', 'system', function() {
      elgg_register_plugin_hook_handler('get_sql', 'access', 'friends_of_acl_get_access_sql_clauses');
      elgg_register_plugin_hook_handler('access:collections:write', 'user', 'friends_of_acl_access_collections_write');
    });
    
    
    /**
     * Populates access WHERE sql clauses
     *
     * @param string $hook   "get_sql"
     * @param string $type   "access"
     * @param array  $return Clauses
     * @param array  $params Hook params
     * @return array
     */
    function friends_of_acl_get_access_sql_clauses($hook, $type, $return, $params) {
    
    	$ignore_access = elgg_extract('ignore_access', $params);
    	if ($ignore_access) {
    		return;
    	}
    	$user_guid = elgg_extract('user_guid', $params);
    	if (!$user_guid) {
    		return;
    	}
    
    	$prefix = elgg_get_config('dbprefix');
    	$table_alias = $params['table_alias'] ? $params['table_alias'] . '.' : '';
    	$access_column = $params['access_column'];
    	$owner_guid_column = $params['owner_guid_column'];
    
    	$id = ACCESS_FRIENDS_OF;
    
    	$return['ors'][] = "{$table_alias}{$access_column} = {$id}
    			AND {$table_alias}{$owner_guid_column} IN (
    				SELECT guid_two FROM {$prefix}entity_relationships
    				WHERE relationship='friend' AND guid_one = {$user_guid}
    			)";
    				
    	return $return;
    }
    
    /**
     * Populates write access array with relationship ACLs
     *
     * @param string $hook   "access:collections:write"
     * @param string $type   "user"
     * @param array  $return ACL IDs
     * @param array  $params Hook params
     * @return array
     */
    function friends_of_acl_access_collections_write($hook, $type, $return, $params) {
    
    	$page_owner = elgg_get_page_owner_entity();
    	if ($page_owner instanceof ElggGroup) {
    		return;
    	}
    
    	$return[ACCESS_FRIENDS_OF] = elgg_echo('access:friends_of');
    
    	return $return;
    }
  • whoooaaa thankyou very much ,

    And i want to ask again :D , do you have a code for 'Close friend' access level, my post can be visible by my 'Close friend' (I add X as friend and X adds me as friend) ,

  • Core already has an access level for friends.  If you want "close friends" that are a subset of friends then you can use the core friend collections - create a friend collection, add your close friends, and a new access level for that collection appears.

    Under the hood it's using the access_collections API:

    http://reference.elgg.org/engine_2lib_2access_8php.html#a8515ffedce90f755ed58262eb26c6c65

    http://reference.elgg.org/engine_2lib_2access_8php.html#ac17767a1861da9b6412b42a399153659

  • @Ismayl , I write a blog post and the access level is   "Friend Of" , but when the blog post has been created , the access level becomes "Limited"? why ?

    @Matt Becket , "Close friend" that I mean is = I add X as friend and X adds me as friend. Thank for your reference :)

  • @ismayl : oh I just understand, your code replaces "Friends" with "Friend Of" access level .What if I change my goal., I don't want to change , but I want to add new access level . Is this code can be used for that purpose ?