You are here

function social_album_post_presave in Open Social 10.1.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_album/social_album.module \social_album_post_presave()
  2. 10.0.x modules/social_features/social_album/social_album.module \social_album_post_presave()
  3. 10.2.x modules/social_features/social_album/social_album.module \social_album_post_presave()

Implements hook_ENTITY_TYPE_presave().

File

modules/social_features/social_album/social_album.module, line 159
The Social Album module.

Code

function social_album_post_presave(EntityInterface $entity) {
  if ($entity
    ->isNew() && $entity
    ->bundle() === 'photo' && !$entity->field_album
    ->isEmpty() && $entity->field_recipient_group
    ->isEmpty()) {
    $group_content = \Drupal::entityTypeManager()
      ->getStorage('group_content')
      ->loadByEntity($entity->field_album->entity);
    if ($group_content) {
      $entity->field_recipient_group
        ->setValue(reset($group_content)
        ->getGroup());
    }
  }
}