function social_post_album_preprocess_field__post__type__image__album in Open Social 10.0.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_post/modules/social_post_album/social_post_album.module \social_post_album_preprocess_field__post__type__image__album()
- 10.1.x modules/social_features/social_post/modules/social_post_album/social_post_album.module \social_post_album_preprocess_field__post__type__image__album()
- 10.2.x modules/social_features/social_post/modules/social_post_album/social_post_album.module \social_post_album_preprocess_field__post__type__image__album()
Implements hook_preprocess_field().
File
- modules/
social_features/ social_post/ modules/ social_post_album/ social_post_album.module, line 38 - The Social post album module.
Code
function social_post_album_preprocess_field__post__type__image__album(&$variables) {
$post = $variables['element']['#object'];
if ($post instanceof PostInterface) {
$all_post_fids = \Drupal::database()
->select('post__field_post_image', 'fpi')
->fields('fpi', [
'field_post_image_target_id',
])
->condition('entity_id', $post
->id())
->countQuery()
->execute()
->fetchField();
$visible_fids_count = $post->field_post_image
->count();
$variables['more_posts_count'] = $all_post_fids - $visible_fids_count;
$variables['total_post_image_count'] = $all_post_fids;
foreach ($variables['items'] as $item) {
/** @var \Drupal\Core\Template\Attribute $attributes */
$attributes = $item['attributes'];
$url = Url::fromRoute('social_post_album.image_popup_render_original', [
'post' => $post
->id(),
'first_fid' => $item['content']['#item']->entity->fid->value,
]);
$attributes
->setAttribute('href', $url
->toString())
->setAttribute('data-dialog-type', 'modal')
->setAttribute('data-dialog-options', JSON::encode([
'width' => '100%',
'dialogClass' => 'post',
]))
->addClass('use-ajax');
}
}
}