public function FacebookAlbumController::getAlbumsNext in Facebook Album 8
Fetch the next or previous set of cover photos from the specified page ID
Parameters
\Drupal\block\BlockInterface $block:
null $after: The id for fetching the next set of albums
Return value
\Zend\Diactoros\Response\JsonResponse A json object containing an html template and after id
1 call to FacebookAlbumController::getAlbumsNext()
- FacebookAlbumController::getAlbums in src/
Controller/ FacebookAlbumController.php - Fetch first set of albums specified in the settings menu
1 string reference to 'FacebookAlbumController::getAlbumsNext'
File
- src/
Controller/ FacebookAlbumController.php, line 63 - Contains \Drupal\facebook_album\Controller\FacebookAlbumController.
Class
- FacebookAlbumController
- Controller for Facebook Album.
Namespace
Drupal\facebook_album\ControllerCode
public function getAlbumsNext(BlockInterface $block, $after = NULL) {
$settings = $block
->get('settings');
$limit = $settings['album_limit'];
if ($limit < 1) {
$limit = NULL;
}
else {
// ensure that ID's can't be passed in to retrieve albums
// if limit has been set to a non-zero number
$after = NULL;
}
$path = $settings['page_id'] . '/albums';
$parameters = [
'after' => $after,
'limit' => $limit,
'fields' => 'location,description,name,cover_photo.fields(images)',
];
$response = $this
->makeRequest($path, $parameters);
// Filter out any albums from the config
$filtered_content = $this
->filterAlbums($response['data'], $settings['albums'], $settings['album_visibility']);
// Build json response
$json_response = [];
$render = [
'#theme' => 'facebook_album_covers',
'#settings' => $settings,
'#photos' => $filtered_content,
];
$json_response['data']['content'] = \Drupal::service('renderer')
->render($render);
if (isset($response['paging']) && isset($response['paging']['next']) && $limit == NULL) {
$json_response['data']['after'] = $response['paging']['cursors']['after'];
}
else {
$json_response['data']['after'] = NULL;
}
return new JsonResponse($json_response);
}