/** * {@inheritdoc} */ public function build() { // Retrieve existing configuration for this block. // @todo migrate variables to block configuration. $config = $this->getConfiguration(); $count = isset($config['image_count']) ? $config['image_count'] : 10; if (\Drupal::currentUser()->hasPermission('view photo') && $content = _photos_block_image('latest', $count, 'photos/image')) { return array( '#markup' => $content ); } }
/** * {@inheritdoc} */ public function build() { // Retrieve existing configuration for this block. // @todo migrate variables to block configuration. $config = $this->getConfiguration(); $count = isset($config['image_count']) ? $config['image_count'] : 10; // Check current path for args to find uid. $current_path = \Drupal::service('path.current')->getPath(); $arg = explode('/', $current_path); if (isset($arg[2])) { if ($arg[1] == 'photos' && isset($arg[3])) { switch ($arg[2]) { case 'image': $uid = db_query('SELECT uid FROM {file_managed} WHERE fid = :uid', array(':uid' => $arg[3]))->fetchField(); break; case 'user': $uid = $arg[3]; } } if ($arg[1] == 'node' && is_numeric($arg[2])) { $uid = db_query('SELECT uid FROM {node_field_data} WHERE nid = :nid', array(':nid' => $arg[2]))->fetchField(); } } if (!isset($uid)) { $user = \Drupal::currentUser(); $uid = $user->id(); } if ($uid && ($block_info = _photos_block_image('user', $count, 'photos/user/' . $uid . '/image', $uid))) { return array( '#markup' => $block_info['content'], '#title' => $block_info['title'] ); } }
/** * Returns an overview of recent albums and photos. * * @return string * A HTML-formatted string with the administrative page content. * */ public function contentOverview() { $account = \Drupal::currentUser(); $content = array(); if ($account->id() && $account->hasPermission('create photo')) { $val = _photos_block_image('user', 5, 'photos/user/' . $account->id() . '/image', $account->id()); $content['user']['image'] = isset($val['content']) ? $val['content'] : ''; $val = $this->albumViews('user', 5, 'photos/user/' . $account->id() . '/album', $account->id()); $content['user']['album'] = $val['content'] ? $val['content'] : ''; } $content['site']['image'] = _photos_block_image('latest', 5, 'photos/image'); $content['site']['album'] = $this->albumViews('latest', 5, 'photos/album'); return array( '#theme' => 'photos_default', '#content' => $content, '#empty' => t('No photos available.'), ); }