You are here

function hook_groupmedia_attach_group_alter in Group Media 8.2

Allows to conditionally add the media to given group.

If media should NOT be processed add FALSE value to the $result array. If at least 1 FALSE will be in the $result array after all modules react on the hook, the media will not be processed. If no value is added to the $result array it is assumed that media is allowed to be processed, no restrictions.

Parameters

array $result: Sets whether media should be attached to given group.

\Drupal\media\MediaInterface $media: Media to check.

\Drupal\group\Entity\GroupInterface $group: Group to check.

1 invocation of hook_groupmedia_attach_group_alter()
AttachMediaToGroup::shouldBeAttached in src/AttachMediaToGroup.php
Allow other modules to check whether media should be attached to group.

File

./groupmedia.api.php, line 65
Describes hooks provided by groupmedia module.

Code

function hook_groupmedia_attach_group_alter(array &$result, MediaInterface $media, GroupInterface $group) {
  $account = \Drupal::currentUser();
  if ($media
    ->hasField('field_include') && $group
    ->getMember($account)) {
    $result[] = FALSE;
  }
}