/**
  * Implements Drupal\file\FileUsage\FileUsageInterface::add().
  */
 public function add(FileInterface $file, $module, $type, $id, $count = 1)
 {
     // Make sure that a used file is permanent.
     if (!$file->isPermanent()) {
         $file->setPermanent();
         $file->save();
     }
 }
Esempio n. 2
0
 /**
  * Asserts that two files have the same values (except timestamp).
  *
  * @param \Drupal\file\FileInterface $before
  *   File object to compare.
  * @param \Drupal\file\FileInterface $after
  *   File object to compare.
  */
 function assertFileUnchanged(FileInterface $before, FileInterface $after)
 {
     $this->assertEqual($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', array('%file1' => $before->id(), '%file2' => $after->id())), 'File unchanged');
     $this->assertEqual($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', array('%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id())), 'File unchanged');
     $this->assertEqual($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', array('%file1' => $before->getFilename(), '%file2' => $after->getFilename())), 'File unchanged');
     $this->assertEqual($before->getFileUri(), $after->getFileUri(), t('File path is the same: %file1 == %file2.', array('%file1' => $before->getFileUri(), '%file2' => $after->getFileUri())), 'File unchanged');
     $this->assertEqual($before->getMimeType(), $after->getMimeType(), t('File MIME type is the same: %file1 == %file2.', array('%file1' => $before->getMimeType(), '%file2' => $after->getMimeType())), 'File unchanged');
     $this->assertEqual($before->getSize(), $after->getSize(), t('File size is the same: %file1 == %file2.', array('%file1' => $before->getSize(), '%file2' => $after->getSize())), 'File unchanged');
     $this->assertEqual($before->isPermanent(), $after->isPermanent(), t('File status is the same: %file1 == %file2.', array('%file1' => $before->isPermanent(), '%file2' => $after->isPermanent())), 'File unchanged');
 }
Esempio n. 3
0
 /**
  * Asserts that a file's status is set to permanent in the database.
  */
 function assertFileIsPermanent(FileInterface $file, $message = NULL)
 {
     $message = isset($message) ? $message : format_string('File %file is permanent.', array('%file' => $file->getFileUri()));
     $this->assertTrue($file->isPermanent(), $message);
 }