Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668
This commit is contained in:
parent
f32e58e4b1
commit
8e18df8c36
3062 changed files with 15044 additions and 172506 deletions
|
@ -5,7 +5,6 @@
|
|||
* Field module functionality for the File module.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldFilteredMarkup;
|
||||
use Drupal\Core\Render\Element;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
(function ($, Drupal) {
|
||||
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Attach behaviors to the file fields passed in the settings.
|
||||
|
@ -142,7 +142,7 @@
|
|||
if (extensionPattern.length > 1 && this.value.length > 0) {
|
||||
var acceptableMatch = new RegExp('\\.(' + extensionPattern + ')$', 'gi');
|
||||
if (!acceptableMatch.test(this.value)) {
|
||||
var error = Drupal.t("The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.", {
|
||||
var error = Drupal.t('The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.', {
|
||||
// According to the specifications of HTML5, a file upload control
|
||||
// should not reveal the real local path to the file that a user
|
||||
// has selected. Some web browsers implement this restriction by
|
||||
|
|
|
@ -18,7 +18,6 @@ use Drupal\Component\Utility\NestedArray;
|
|||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
use Drupal\file\FileUsage\FileUsageInterface;
|
||||
|
||||
// Load all Field module hooks for File.
|
||||
require_once __DIR__ . '/file.field.inc';
|
||||
|
|
|
@ -11,7 +11,14 @@ source:
|
|||
description_field: 1
|
||||
process:
|
||||
entity_type: 'constants/entity_type'
|
||||
bundle: node_type
|
||||
bundle:
|
||||
-
|
||||
plugin: migration
|
||||
migration: d6_node_type
|
||||
source: node_type
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
field_name: 'constants/name'
|
||||
settings: 'constants/settings'
|
||||
'settings/file_extensions': file_extensions
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\file;
|
|||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines getter and setter methods for file entity base fields.
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\file\FileUsage;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\DatabaseExceptionWrapper;
|
||||
use Drupal\file\FileInterface;
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,7 @@ class FileItem extends EntityReferenceItem {
|
|||
public static function defaultFieldSettings() {
|
||||
return array(
|
||||
'file_extensions' => 'txt',
|
||||
'file_directory' => '',
|
||||
'file_directory' => '[date:custom:Y]-[date:custom:m]',
|
||||
'max_filesize' => '',
|
||||
'description_field' => 0,
|
||||
) + parent::defaultFieldSettings();
|
||||
|
@ -267,7 +267,22 @@ class FileItem extends EntityReferenceItem {
|
|||
* @see token_replace()
|
||||
*/
|
||||
public function getUploadLocation($data = array()) {
|
||||
$settings = $this->getSettings();
|
||||
return static::doGetUploadLocation($this->getSettings(), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the URI for a file field.
|
||||
*
|
||||
* @param array $settings
|
||||
* The array of field settings.
|
||||
* @param array $data
|
||||
* An array of token objects to pass to token_replace().
|
||||
*
|
||||
* @return string
|
||||
* An unsanitized file directory URI with tokens replaced. The result of
|
||||
* the token replacement is then converted to plain text and returned.
|
||||
*/
|
||||
protected static function doGetUploadLocation(array $settings, $data = []) {
|
||||
$destination = trim($settings['file_directory'], '/');
|
||||
|
||||
// Replace tokens. As the tokens might contain HTML we convert it to plain
|
||||
|
@ -312,7 +327,7 @@ class FileItem extends EntityReferenceItem {
|
|||
$settings = $field_definition->getSettings();
|
||||
|
||||
// Prepare destination.
|
||||
$dirname = $settings['uri_scheme'] . '://' . $settings['file_directory'];
|
||||
$dirname = static::doGetUploadLocation($settings);
|
||||
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY);
|
||||
|
||||
// Generate a file entity.
|
||||
|
|
|
@ -17,7 +17,6 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\Core\Render\ElementInfoManagerInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\file\Element\ManagedFile;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\file\Entity\File;
|
||||
|
|
|
@ -23,6 +23,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class CckFile extends ProcessPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The migration process plugin, configured for lookups in d6_file.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrateProcessInterface
|
||||
*/
|
||||
protected $migrationPlugin;
|
||||
|
||||
/**
|
||||
|
@ -92,6 +97,8 @@ class CckFile extends ProcessPluginBase implements ContainerFactoryPluginInterfa
|
|||
'target_id' => $fid,
|
||||
'display' => $value['list'],
|
||||
'description' => isset($options['description']) ? $options['description'] : '',
|
||||
'alt' => isset($options['alt']) ? $options['alt'] : '',
|
||||
'title' => isset($options['title']) ? $options['title'] : '',
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\file\Plugin\views\field;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\views\ResultRow;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
namespace Drupal\file\Tests;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Tests for download/file transfer functions.
|
||||
*
|
||||
|
|
|
@ -19,20 +19,29 @@ class FileFieldPathTest extends FileFieldTestBase {
|
|||
* Tests the normal formatter display on node display.
|
||||
*/
|
||||
function testUploadPath() {
|
||||
/** @var \Drupal\node\NodeStorageInterface $node_storage */
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$field_name = strtolower($this->randomMachineName());
|
||||
$type_name = 'article';
|
||||
$this->createFileField($field_name, 'node', $type_name);
|
||||
/** @var \Drupal\file\FileInterface $test_file */
|
||||
$test_file = $this->getTestFile('text');
|
||||
|
||||
// Create a new node.
|
||||
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
|
||||
|
||||
// Check that the file was uploaded to the file root.
|
||||
// Check that the file was uploaded to the correct location.
|
||||
$node_storage->resetCache(array($nid));
|
||||
$node = $node_storage->load($nid);
|
||||
$node_file = File::load($node->{$field_name}->target_id);
|
||||
$this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
|
||||
/** @var \Drupal\file\FileInterface $node_file */
|
||||
$node_file = $node->{$field_name}->entity;
|
||||
$date_formatter = $this->container->get('date.formatter');
|
||||
$expected_filename =
|
||||
'public://' .
|
||||
$date_formatter->format(REQUEST_TIME, 'custom', 'Y') . '-' .
|
||||
$date_formatter->format(REQUEST_TIME, 'custom', 'm') . '/' .
|
||||
$test_file->getFilename();
|
||||
$this->assertPathMatch($expected_filename, $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
|
||||
|
||||
// Change the path to contain multiple subdirectories.
|
||||
$this->updateFileField($field_name, $type_name, array('file_directory' => 'foo/bar/baz'));
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\file\Tests;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\file\Entity\File;
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
namespace Drupal\file\Tests;
|
||||
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\Core\Entity\EntityStorageException;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
|
||||
|
||||
/**
|
||||
* File saving tests.
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\file\Unit\Plugin\migrate\process\d6\CckFileTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\file\Unit\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\file\Plugin\migrate\process\d6\CckFile;
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @group file
|
||||
*/
|
||||
class CckFileTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests that alt and title attributes are included in transformed values.
|
||||
*/
|
||||
public function testTransformAltTitle() {
|
||||
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
|
||||
$row = $this->prophesize(Row::class)->reveal();
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
|
||||
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
|
||||
$migration_plugin->transform(1, $executable, $row, 'foo')->willReturn(1);
|
||||
|
||||
$plugin = new CckFile(array(), 'd6_cck_file', array(), $migration, $migration_plugin->reveal());
|
||||
|
||||
$options = array(
|
||||
'alt' => 'Foobaz',
|
||||
'title' => 'Wambooli',
|
||||
);
|
||||
$value = array(
|
||||
'fid' => 1,
|
||||
'list' => TRUE,
|
||||
'data' => serialize($options),
|
||||
);
|
||||
|
||||
$transformed = $plugin->transform($value, $executable, $row, 'foo');
|
||||
$expected = array(
|
||||
'target_id' => 1,
|
||||
'display' => TRUE,
|
||||
'description' => '',
|
||||
'alt' => 'Foobaz',
|
||||
'title' => 'Wambooli',
|
||||
);
|
||||
$this->assertSame($expected, $transformed);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue