Closed (fixed)
Project:
Album Photos
Version:
8.x-4.2
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
5 Jan 2020 at 17:30 UTC
Updated:
20 Jan 2020 at 14:59 UTC
Jump to comment: Most recent
I would like to create a block displaying one random image selected from any of the uploaded pictures. I have searched and found a number of posts that suggest this is possible with earlier versions of Album Photos, including one promise to add this feature in D6 (https://www.drupal.org/project/photos/issues/316849). Some mention "use Views".
I cannot seem to figure this out. Is this possible with the current version? If so, can someone provide or direct me to specific detailed instructions how to accomplish this?
Comments
Comment #2
nathaniel commentedThere should be a block called "Random Images". The block has a setting for how many images are displayed that can be set to 1.
Comment #3
nathaniel commentedActually it looks like the random images block gets cached, so it displays the same image until the cache is cleared. We can add the following code for now to disable the block cache:
src/Plugin/Block/PhotosRandomImages.php
To add the block:
Structure > Block Layout, click "Place block" in the region you want the block to appear. Scroll down to category "photos" or Filter by "Random Images".
Note: we might want to think about making it ajax / lazy load somehow, if that is more efficient than disabling the block cache.
Comment #6
nathaniel commentedComment #7
ddv commentedFirst off, thankyou for your quick response.
I am so tantalizingly close. I followed your instructions to add the block in #3 (although, I could not find any filter settings, just the category "Photos") , installed pupload and colorbox modules, created an photo album node, copied a directory (in configure) into that album. The block did appear, but ONLY when looking at one of the pages of that particular album node (not even when looking at a specific photo or the Recent Albums page) and ONLY when logged in as administrator.
I tried setting the permissions to allow all roles to view photos but that made no difference. I eventually realized Permissions by Term was preventing access so I added a term field to the album form and selected a term viewable by all roles. Now the block was visible by all but still only when on the specific album node page.
The image in the block was a bit small, so I tried changing the pager, cover and thumb sizes to 200 x 200. The block disappeared. I tried changing the sizes back to the default 100 x 100. The block was still unavailable. I tried deleting the block and recreating it without success. I eventually deleted the album, Photos Access and Photos modules and reinstalling Photos only. I set the pager, cover and thumb sizes to 200 x 200 before creating the album and placing the block. That seemed to work, the block is back with a slightly larger image -- but again, only when viewing the album node itself, not on any other page.
I have tried experimenting in the block configuration page. For example, I tried setting "Show for listed pages" to , but that not only did not make the block visible on the front page, it disabled the block on the album page.
Any idea what I'm doing wrong here?
I did finally add your code snippet to src/Plugin/Block/PhotosRandomImages.php and it does ensure the images are not cached.
Comment #8
ddv commentedOh, BTW, I am running Drupal 8.8.1 on php 7.2, if that makes a difference.
Comment #9
ddv commentedSON OF A PUP! I figured it out. In the Configure Block setting, I had ticked "Photos" under Content Type, thinking that referred to the type of content IN the block. I deselected that and now the block appears on every page, featuring a different photo every refresh.
I'm so embarrassed...
Thanks again for your efforts.
Comment #10
nathaniel commentedInteresting, thanks for the feedback. Sounds like there may be something about permission by term preventing the block from appearing on other pages. Or possibly some other module configuration. I'll try to test a bit. If you have steps to reproduce on a fresh install that would help debug the issue.
I know the photo information block will only appear on image pages, but random images / recent images should appear on any page.
Comment #11
nathaniel commentedOh, great, no problem!