You are here

private function AttachMediaToGroup::shouldBeAttached in Group Media 8.2

Allow other modules to check whether media should be attached to group.

Parameters

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

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

Return value

bool Returns TRUE if the media should be attached to the group, FALSE in other case.

1 call to AttachMediaToGroup::shouldBeAttached()
AttachMediaToGroup::assignMediaToGroups in src/AttachMediaToGroup.php
Assign media items to groups.

File

src/AttachMediaToGroup.php, line 259

Class

AttachMediaToGroup
Class AttachMediaToGroup.

Namespace

Drupal\groupmedia

Code

private function shouldBeAttached(MediaInterface $media, GroupInterface $group) {
  $result = [];
  $this->moduleHandler
    ->alter('groupmedia_attach_group', $result, $media, $group);
  if (!is_array($result)) {
    return FALSE;
  }

  // If at least 1 module says "No", the media will not be attached.
  foreach ($result as $item) {
    if (!$item) {
      return FALSE;
    }
  }

  // Otherwise - process.
  return TRUE;
}