Update to Drupal 8.1.2. For more information, see https://www.drupal.org/project/drupal/releases/8.1.2

This commit is contained in:
Pantheon Automation 2016-06-02 15:56:09 -07:00 committed by Greg Anderson
parent 9eae24d844
commit 28556d630e
1322 changed files with 6699 additions and 2064 deletions

View file

@ -97,7 +97,7 @@ class ManagedFile extends FormElement {
// Temporary files that belong to other users should never be
// allowed.
if ($file->isTemporary()) {
if ($file->getOwnerId() != \Drupal::currentUser()->id()) {
if ($file->getOwnerId() != \Drupal::currentUser()->id()) {
$force_default = TRUE;
break;
}

View file

@ -13,6 +13,8 @@ use Drupal\user\UserInterface;
/**
* Defines the file entity class.
*
* @ingroup file
*
* @ContentEntityType(
* id = "file",
* label = @Translation("File"),
@ -186,7 +188,11 @@ class File extends ContentEntityBase implements FileInterface {
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
$this->setSize(filesize($this->getFileUri()));
// The file itself might not exist or be available right now.
$uri = $this->getFileUri();
if ($size = @filesize($uri)) {
$this->setSize($size);
}
}
/**

View file

@ -6,6 +6,8 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
/**
@ -43,6 +45,16 @@ class FileAccessControlHandler extends EntityAccessControlHandler {
}
}
if ($operation == 'delete' || $operation == 'update') {
$account = $this->prepareUser($account);
$file_uid = $entity->get('uid')->getValue();
// Only the file owner can delete and update the file entity.
if ($account->id() == $file_uid[0]['target_id']) {
return AccessResult::allowed();
}
return AccessResult::forbidden();
}
// No opinion.
return AccessResult::neutral();
}
@ -63,4 +75,30 @@ class FileAccessControlHandler extends EntityAccessControlHandler {
return file_get_file_references($file, NULL, EntityStorageInterface::FIELD_LOAD_REVISION, NULL);
}
/**
* {@inheritdoc}
*/
protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
// No user can edit the status of a file. Prevents saving a new file as
// persistent before even validating it.
if ($field_definition->getName() === 'status' && $operation === 'edit') {
return AccessResult::forbidden();
}
return parent::checkFieldAccess($operation, $field_definition, $account, $items);
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
// The file entity has no "create" permission because by default Drupal core
// does not allow creating file entities independently. It allows you to
// create file entities that are referenced from another entity
// (e.g. an image for a article). A contributed module is free to alter
// this to allow file entities to be created directly.
// @todo Update comment to mention REST module when
// https://www.drupal.org/node/1927648 is fixed.
return AccessResult::neutral();
}
}

View file

@ -8,6 +8,8 @@ use Drupal\Core\Entity\EntityChangedInterface;
/**
* Defines getter and setter methods for file entity base fields.
*
* @ingroup file
*/
interface FileInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
@ -113,4 +115,5 @@ interface FileInterface extends ContentEntityInterface, EntityChangedInterface,
* Creation timestamp of the file entity.
*/
public function getCreatedTime();
}

View file

@ -23,4 +23,5 @@ interface FileStorageInterface extends ContentEntityStorageInterface {
* An integer containing the number of bytes used.
*/
public function spaceUsed($uid = NULL, $status = FILE_STATUS_PERMANENT);
}

View file

@ -107,4 +107,5 @@ class DatabaseFileUsageBackend extends FileUsageBase {
}
return $references;
}
}

View file

@ -32,4 +32,5 @@ abstract class FileUsageBase implements FileUsageInterface {
$file->save();
}
}
}

View file

@ -64,7 +64,7 @@ interface FileUsageInterface {
* A nested array with usage data. The first level is keyed by module name,
* the second by object type and the third by the object id. The value of
* the third level contains the usage count.
*
*/
public function listUsage(FileInterface $file);
}

View file

@ -372,7 +372,8 @@ class FileWidget extends WidgetBase implements ContainerFactoryPluginInterface {
);
if (isset($item['display'])) {
$element['display']['#value'] = $item['display'] ? '1' : '';
} else {
}
else {
$element['display']['#value'] = $element['#display_default'];
}
}

View file

@ -168,4 +168,5 @@ class DownloadTest extends FileManagedTestBase {
$file->delete();
}
}

View file

@ -89,4 +89,5 @@ class FileFieldPathTest extends FileFieldTestBase {
$result = preg_match('/' . preg_quote($base_path, '/') . '(_[0-9]+)?\.' . preg_quote($extension, '/') . '/', $actual_path);
$this->assertTrue($result, $message);
}
}

View file

@ -64,4 +64,5 @@ class FileFieldRSSContentTest extends FileFieldTestBase {
);
$this->assertRaw($test_element, 'File field RSS enclosure is displayed when viewing the RSS feed.');
}
}

View file

@ -138,4 +138,5 @@ class FileFieldRevisionTest extends FileFieldTestBase {
$this->assertFileNotExists($node_file_r1, 'Original file is deleted after deleting the entire node with two revisions remaining.');
$this->assertFileEntryNotExists($node_file_r1, 'Original file entry is deleted after deleting the entire node with two revisions remaining.');
}
}

View file

@ -191,7 +191,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$check_field_name = $field_name;
}
$this->assertIdentical((string) $button['name'], $check_field_name . '_' . $key. '_remove_button');
$this->assertIdentical((string) $button['name'], $check_field_name . '_' . $key . '_remove_button');
}
// "Click" the remove button (emulating either a nojs or js submission).

View file

@ -65,4 +65,5 @@ class FileManagedAccessTest extends FileManagedTestBase {
$this->assertFalse($file->access('view', $account), 'Private file is not viewable to anonymous user');
$this->assertFalse($file->access('download', $account), 'Private file is not downloadable to anonymous user');
}
}

View file

@ -171,4 +171,27 @@ class FileManagedFileElementTest extends FileFieldTestBase {
$this->assertRaw('The file referenced by the Managed <em>file &amp; butter</em> field does not exist.');
}
/**
* Ensure a file entity can be saved when the file does not exist on disk.
*/
public function testFileRemovedFromDisk() {
$this->drupalGet('file/test/1/0/1');
$test_file = $this->getTestFile('text');
$file_field_name = 'files[nested_file][]';
$edit = [$file_field_name => drupal_realpath($test_file->getFileUri())];
$this->drupalPostForm(NULL, $edit, t('Upload'));
$this->drupalPostForm(NULL, array(), t('Save'));
$fid = $this->getLastFileId();
/** @var $file \Drupal\file\FileInterface */
$file = $this->container->get('entity_type.manager')->getStorage('file')->load($fid);
$file->setPermanent();
$file->save();
$this->assertTrue(file_unmanaged_delete($file->getFileUri()));
$file->save();
$this->assertTrue($file->isPermanent());
$file->delete();
}
}

View file

@ -75,9 +75,9 @@ class FilePrivateTest extends FileFieldTestBase {
$this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish'));
$new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$edit[$field_name . '[0][fids]'] = $node_file->id();
$this->drupalPostForm('node/' . $new_node->id() .'/edit', $edit, t('Save and keep published'));
$this->drupalPostForm('node/' . $new_node->id() . '/edit', $edit, t('Save and keep published'));
// Make sure the form submit failed - we stayed on the edit form.
$this->assertUrl('node/' . $new_node->id() .'/edit');
$this->assertUrl('node/' . $new_node->id() . '/edit');
// Check that we got the expected constraint form error.
$constraint = new ReferenceAccessConstraint();
$this->assertRaw(SafeMarkup::format($constraint->message, array('%type' => 'file', '%id' => $node_file->id())));
@ -111,4 +111,5 @@ class FilePrivateTest extends FileFieldTestBase {
$this->drupalGet($file_url);
$this->assertResponse(403, 'Confirmed that access is denied for another user to the temporary file.');
}
}

View file

@ -93,4 +93,5 @@ class FileTokenReplaceTest extends FileFieldTestBase {
$this->assertEqual($output, $expected, format_string('Unsanitized file token %token replaced.', array('%token' => $input)));
}
}
}

View file

@ -20,4 +20,5 @@ class RemoteFileSaveUploadTest extends SaveUploadTest {
parent::setUp();
$this->config('system.file')->set('default_scheme', 'dummy-remote')->save();
}
}

View file

@ -358,4 +358,5 @@ class SaveUploadTest extends FileManagedTestBase {
'@destination' => 'temporary://' . $test_directory . '/' . $this->image->getFilename()
)), 'Found upload error log entry.');
}
}