/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $fid = NULL) { $select_type = _photos_select_sub_album(); if ($select_type[0]) { $form['title']['#markup'] = '<h2>' . t('Please select sub-album') . ': ' . '</h2>'; $query = db_select('photos_node', 'p') ->fields('p', array('nid')) ->condition('fid', $fid); $result = $query->execute(); $select_sub = array(); foreach ($result as $sub) { $select_sub[] = $sub->nid; } if (!isset($select_sub[0])) $select_sub[] = 0; $query = db_select('node_field_data', 'n')->extend('Drupal\Core\Database\Query\PagerSelectExtender'); $query->fields('n', array('nid', 'title')) ->condition('n.type', $select_type, 'IN') ->condition('n.nid', $select_sub, 'NOT IN') ->limit(50); $result = $query->execute(); $form['sub']['#tree'] = TRUE; $true = FALSE; foreach ($result as $node) { $form['sub'][$node->id()] = array( '#type' => 'checkbox', // @todo update URL , array('attributes' => array('target' => '_blank')). '#title' => \Drupal::l($node->getTitle(), Url::fromUri('base:node/' . $node->id())), ); $true = TRUE; } if ($true) { $form['fid'] = array( '#type' => 'value', '#value' => $fid ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Send confirmation'), '#submit' => array('_photos_to_sub_submit') ); } else { $form['help']['#markup'] = t('There are no additional sub albums available.'); } } else { $form['help']['#markup'] = t('Sub-album feature is not turned on.'); } return $form; }
/** * Returns content for single image. * * @return string * A HTML-formatted string with the administrative page content. * */ public function contentOverview() { $fid = \Drupal::routeMatch()->getParameter('file'); if (!is_numeric($fid)) { throw new NotFoundHttpException(); } $user = \Drupal::currentUser(); $query = db_select('file_managed', 'f'); $query->join('photos_image', 'p', 'p.fid = f.fid'); $query->join('photos_album', 'a', 'p.pid = a.pid'); $query->join('node', 'n', 'n.nid = p.pid'); $query->join('users_field_data', 'u', 'u.uid = f.uid'); $query->fields('f', array('uri', 'filemime', 'created', 'filename')) ->fields('p') ->fields('a', array('data')) ->fields('u', array('uid', 'name')); $query->condition('p.fid', $fid); $query->addTag('node_access'); $image = $query->execute()->fetchObject(); if (!$image) { throw new NotFoundHttpException(); } $image = photos_get_info(0, $image); $node = \Drupal::entityManager()->getStorage('node')->load($image->pid); if (_photos_access('imageEdit', $node)) { $image->ajax['edit_url'] = Url::fromUri('base:photos/image/' . $image->fid . '/update')->toString(); if (_photos_select_sub_album()) { // Add image to sub-album. $url = Url::fromUri('base:photos/image/' . $image->fid . '/to_sub'); $image->links['to_sub'] = l(t('Add to sub-album...'), $url, array( 'attributes' => array( 'class' => array('colorbox') ) )); } // Set album cover. $url = Url::fromRoute('photos.album.update.cover', array('node' => $image->pid, 'file' => $fid)); $image->links['cover'] = \Drupal::l(t('Set to Cover'), $url, array( 'query' => drupal_get_destination()) ); } $image->class = array( 'title_class' => '', 'des_class' => '', ); $image->id = array( 'des_edit' => '', 'title_edit' => '' ); $edit = _photos_access('imageEdit', $node); if ($edit) { // Image edit link. $url = Url::fromUri('base:photos/image/' . $image->fid . '/edit'); $image->ajax['edit_link'] = \Drupal::l(t('Edit'), $url, array( 'query' => array( 'destination' => 'photos/image/' . $image->fid ), 'attributes' => array( 'class' => array('colorbox-load', 'photos-edit-edit') ) )); $image->class = array( 'title_class' => ' jQueryeditable_edit_title', 'des_class' => ' jQueryeditable_edit_des', ); $image->id = array( 'des_edit' => ' id="photos-image-edit-des-' . $image->fid . '"', 'title_edit' => ' id="photos-image-edit-title-' . $image->fid . '"' ); $jeditable_library = \Drupal::service('library.discovery')->getLibraryByName('photos', 'photos.jeditable'); } if (_photos_access('imageDelete', $node)) { // Image delete link. $url = Url::fromUri('base:photos/image/' . $image->fid . '/delete'); $image->ajax['del_link'] = \Drupal::l(t('Delete'), $url, array( 'query' => array( 'destination' => 'node/' . $image->pid ), 'attributes' => array( 'class' => array('colorbox-load', 'photos-edit-delete') ) )); } if (\Drupal::config('photos.settings')->get('photos_vote')) { // @todo votingapi. $render_vote = array( '#theme' => 'photos_vote', '#fid' => $fid ); // $image->vote = $render_vote; } if (\Drupal::config('photos.settings')->get('photos_comment')) { // Comment integration. $render_comment = array( '#theme' => 'photos_comment_count', '#comcount' => $image->comcount ); $image->links['comment'] = $render_comment; } // @todo $uid? if (FALSE && $uid) { // User images. $pager_type = 'uid'; $pager_id = $uid; } elseif (isset($_GET['photos_sub'])) { // Sub-album images. $pager_type = 'sub'; $pager_id = (int)$_GET['photos_sub']; } else { // Album images. $pager_type = 'pid'; $pager_id = $image->pid; } $data = unserialize($image->data); $style_name = isset($data['view_imagesize']) ? $data['view_imagesize'] : \Drupal::config('photos.settings')->get('photos_display_view_imagesize'); // Necessary when upgrading from D6 to D7. // @todo remove? $image_styles = image_style_options(FALSE); if (!isset($image_styles[$style_name])) { $style_name = \Drupal::config('photos.settings')->get('photos_display_view_imagesize'); } // Display all sizes link to share code? $all_sizes_link = \Drupal::config('photos.settings')->get('photos_print_sizes'); if ($all_sizes_link < 2) { // Display full page or colorbox. $colorbox = array(); if ($all_sizes_link == 1) { $colorbox = array( 'query' => array( 'iframe' => 'true', 'height' => 650, 'width' => 850 ), 'attributes' => array( 'class' => array('colorbox-load') ) ); } $url = Url::fromUri('base:photos/zoom/' . $fid); $image->links['more'] = \Drupal::l(t('All sizes'), $url, $colorbox); } $image->links['pager'] = $this->imagePager($fid, $pager_id, $pager_type); $image->view = array( '#theme' => 'photos_image_html', '#style_name' => $style_name, '#image' => $image, '#cache' => array( 'tags' => array( 'photos:image:' . $fid ) ) ); // Get comments. $image->comment['view'] = _photos_comment($fid, $image->comcount, $node); if (!\Drupal::config('photos.settings')->get('photos_image_count')) { $count = 1; db_update('photos_image') ->fields(array('count' => $count)) ->expression('count', 'count + :count', array(':count' => $count)) ->condition('fid', $fid) ->execute(); } $image->title = \Drupal\Component\Utility\SafeMarkup::checkPlain($image->title); $image->des = \Drupal\Component\Utility\SafeMarkup::checkPlain($image->des); $GLOBALS['photos'][$image->fid . '_pid'] = $image->pid; $image_view = array( '#theme' => 'photos_image_view', '#image' => $image, '#display_type' => 'view', '#cache' => array( 'tags' => array( 'photos:image:' . $fid ) ) ); // Check for Jeditable library. // @todo move to static public function? if ($edit && isset($jeditable_library['js']) && file_exists($jeditable_library['js'][0]['data'])) { $image_view['#attached']['library'][] = 'photos/photos.jeditable'; } return $image_view; }