public static function PhotosAlbum::userAlbumOptions in Album Photos 8.4
Same name and namespace in other branches
- 8.5 src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::userAlbumOptions()
- 6.0.x src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::userAlbumOptions()
User albums.
2 calls to PhotosAlbum::userAlbumOptions()
- CreatePhotosAlbumTest::testCreatePhotosAlbum in tests/
src/ Kernel/ CreatePhotosAlbumTest.php - Tests creating a photo album node.
- PhotosImageEditForm::buildForm in src/
Form/ PhotosImageEditForm.php - Form constructor.
File
- src/
PhotosAlbum.php, line 732
Class
- PhotosAlbum
- Create an album object.
Namespace
Drupal\photosCode
public static function userAlbumOptions($uid = 0, $current = 0) {
if (!$uid) {
$uid = \Drupal::currentUser()
->id();
}
$output = [];
// Query user albums.
$db = \Drupal::database();
$query = $db
->select('node_field_data', 'n');
$query
->join('photos_album', 'a', 'a.pid = n.nid');
$query
->fields('n', [
'nid',
'title',
]);
$query
->condition('n.uid', $uid);
$query
->orderBy('n.nid', 'DESC');
$result = $query
->execute();
$true = FALSE;
foreach ($result as $a) {
$choice = new \stdClass();
$choice->option = [
$a->nid => $a->title,
];
$output[$a->nid] = $choice;
$true = TRUE;
}
if ($current) {
$choice = new \stdClass();
$choice->option = [
$current[0] => $current[1],
];
$output[$a->nid] = $choice;
}
if (!$true) {
$output = [
t('You do not have an album yet.'),
];
}
return $output;
}