unlcms / UNL-CMS-2

Previous Drupal 8 implementation at UNL. See https://github.com/unlcms/project-herbie for newer project.
GNU General Public License v2.0
3 stars 8 forks source link

IMCE folder provisioning by group #9

Closed ericras closed 7 years ago

ericras commented 7 years ago

In Drupal 7, the following could be pasted after "/" in the IMCE settings UI:

php: 
        $names = array();
        foreach(views_get_view_result('og_groups_by_user') as $group){
          array_push($names,'statewide/'.$group->field_field_url_path[0]['rendered']['#markup']);
        }
        return $names;

In doesn't look like the D8 version of IMCE supports putting php in the text box. It supports tokens but there's not a [current-user:groups] token. Tokens are kind of meant for a single value, not an array. This probably needs to be accomplished in code.

ericras commented 7 years ago
screen shot 2016-12-23 at 10 36 43 am
ericras commented 7 years ago
$grp_membership_service = \Drupal::service('group.membership_loader');
$grps = $grp_membership_service->loadByUser($user);
foreach ($grps as $grp) {
        $groups[] = $grp->getGroup();
}
kabel commented 7 years ago

Their aren't any hooks for this in the 8.x version (as you alluded to), so we'll likely have to add a patch to support this kind of folder permission injection at http://cgit.drupalcode.org/imce/tree/src/Imce.php?h=8.x-1.x#n107

mfairchild365 commented 7 years ago

There may not be hooks, but there are plugins!

mfairchild365 commented 7 years ago

I made a PR that implements a plugin that will accomplish this: https://github.com/unlcms/imce_groups/pull/1