/** * Implements Drupal\file\FileUsage\FileUsageInterface::listUsage(). */ public function listUsage(FileInterface $file) { $result = $this->connection->select($this->tableName, 'f')->fields('f', array('module', 'type', 'id', 'count'))->condition('fid', $file->id())->condition('count', 0, '>')->execute(); $references = array(); foreach ($result as $usage) { $references[$usage->module][$usage->type][$usage->id] = $usage->count; } return $references; }
protected function setUp() { parent::setUp(); // Use Classy theme for testing markup output. \Drupal::service('theme_handler')->install(['classy']); \Drupal::service('theme_handler')->setDefault('classy'); $this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]); // Create two test users. $this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer comments', 'access comments', 'access content')); $this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'access content')); $this->drupalLogin($this->adminUser); // Create term. $this->term = Term::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => 'tags']); $this->term->save(); // Create image. file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = File::create(['uri' => 'public://example.jpg']); $this->image->save(); // Create article. $article_settings = array('type' => 'article', 'promote' => NODE_PROMOTED, 'field_image' => array(array('target_id' => $this->image->id())), 'field_tags' => array(array('target_id' => $this->term->id()))); $this->article = $this->drupalCreateNode($article_settings); // Create second article to test teaser list. $this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED)); // Create article comment. $this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0); // Create page. $this->page = $this->drupalCreateNode(array('type' => 'page')); // Set URIs. // Image. $image_file = $this->article->get('field_image')->entity; $this->imageUri = ImageStyle::load('large')->buildUrl($image_file->getFileUri()); // Term. $this->termUri = $this->term->url('canonical', array('absolute' => TRUE)); // Article. $this->articleUri = $this->article->url('canonical', array('absolute' => TRUE)); // Page. $this->pageUri = $this->page->url('canonical', array('absolute' => TRUE)); // Author. $this->authorUri = $this->adminUser->url('canonical', array('absolute' => TRUE)); // Comment. $this->articleCommentUri = $this->articleComment->url('canonical', array('absolute' => TRUE)); // Commenter. $this->commenterUri = $this->webUser->url('canonical', array('absolute' => TRUE)); $this->drupalLogout(); }
protected function setUp() { parent::setUp(); $this->base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]); // Create two test users. $this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer comments', 'access comments', 'access content')); $this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'access content')); $this->drupalLogin($this->adminUser); // Create term. $this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => 'tags')); $this->term->save(); // Create image. file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = entity_create('file', array('uri' => 'public://example.jpg')); $this->image->save(); // Create article. $article_settings = array('type' => 'article', 'promote' => NODE_PROMOTED, 'field_image' => array(array('target_id' => $this->image->id())), 'field_tags' => array(array('target_id' => $this->term->id()))); $this->article = $this->drupalCreateNode($article_settings); // Create second article to test teaser list. $this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED)); // Create article comment. $this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0); // Create page. $this->page = $this->drupalCreateNode(array('type' => 'page')); // Set URIs. // Image. $image_file = $this->article->get('field_image')->entity; $this->imageUri = entity_load('image_style', 'large')->buildUrl($image_file->getFileUri()); // Term. $this->termUri = $this->term->url('canonical', array('absolute' => TRUE)); // Article. $this->articleUri = $this->article->url('canonical', array('absolute' => TRUE)); // Page. $this->pageUri = $this->page->url('canonical', array('absolute' => TRUE)); // Author. $this->authorUri = $this->adminUser->url('canonical', array('absolute' => TRUE)); // Comment. $this->articleCommentUri = $this->articleComment->url('canonical', array('absolute' => TRUE)); // Commenter. $this->commenterUri = $this->webUser->url('canonical', array('absolute' => TRUE)); $this->drupalLogout(); }
/** * {@inheritdoc} */ public function getCropEntity(FileInterface $file, $crop_type) { if (Crop::cropExists($file->getFileUri(), $crop_type)) { /** @var \Drupal\crop\CropInterface $crop */ $crop = Crop::findCrop($file->getFileUri(), $crop_type); } else { $values = [ 'type' => $crop_type, 'entity_id' => $file->id(), 'entity_type' => 'file', 'uri' => $file->getFileUri(), ]; $crop = \Drupal::entityTypeManager() ->getStorage('crop') ->create($values); } return $crop; }
/** * Asserts that two files are the same by comparing the fid and filepath. * * @param \Drupal\file\FileInterface $file1 * File object to compare. * @param \Drupal\file\FileInterface $file2 * File object to compare. */ function assertSameFile(FileInterface $file1, FileInterface $file2) { $this->assertEqual($file1->id(), $file2->id(), t('Files have the same ids: %file1 == %file2.', array('%file1' => $file1->id(), '%file2-fid' => $file2->id())), 'Same file'); $this->assertEqual($file1->getFileUri(), $file2->getFileUri(), t('Files have the same path: %file1 == %file2.', array('%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri())), 'Same file'); }
/** * {@inheritdoc} */ public function styleImageSrcData(FileInterface $image_file, $image_style, FileInterface $thumb_file, $thumb_style, $settings) { $check_incompatible = !empty($settings['incompatible_file_action']); $src_data = array(); // Style the main item. $src_data = $this->styleImage($image_file, $image_style, $check_incompatible); // Set thumb data and add it to the source info. $src_data['thumbURL'] = ''; if (!$src_data['juicebox_compatible'] && $image_file->id() == $thumb_file->id()) { $src_data['thumbURL'] = $src_data['imageURL']; } else { $thumb_image_data = $this->styleImage($thumb_file, $thumb_style, $check_incompatible); $src_data['thumbURL'] = $thumb_image_data['imageURL']; } // Check if the linkURL should be customized based on settings. $src_data['linkURL'] = $src_data['unstyled_src']; if ($src_data['juicebox_compatible'] && !empty($settings['linkurl_source']) && $settings['linkurl_source'] == 'image_styled') { $src_data['linkURL'] = $src_data['imageURL']; } // Set the link target directly from the gallery settings. $src_data['linkTarget'] = !empty($settings['linkurl_target']) ? $settings['linkurl_target'] : '_blank'; return $src_data; }