public function AttachMediaToGroup::attach in Group Media 8.2
Attach media items from given entity to the same group(s).
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity to process.
File
- src/
AttachMediaToGroup.php, line 99
Class
- AttachMediaToGroup
- Class AttachMediaToGroup.
Namespace
Drupal\groupmediaCode
public function attach(EntityInterface $entity) {
if (!$this->config
->get('tracking_enabled')) {
return FALSE;
}
$groups = $this
->getContentGroups($entity);
if (empty($groups)) {
return FALSE;
}
$items = $this
->getMediaFromEntity($entity);
if (empty($items)) {
return FALSE;
}
$this
->assignMediaToGroups($items, $groups);
}