update core to 7.36
This commit is contained in:
@@ -92,6 +92,7 @@ function file_field_instance_settings_form($field, $instance) {
|
||||
'#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
|
||||
'#element_validate' => array('_file_generic_settings_extensions'),
|
||||
'#weight' => 1,
|
||||
'#maxlength' => 256,
|
||||
// By making this field required, we prevent a potential security issue
|
||||
// that would allow files of any type to be uploaded.
|
||||
'#required' => TRUE,
|
||||
@@ -251,6 +252,12 @@ function file_field_insert($entity_type, $entity, $field, $instance, $langcode,
|
||||
* Checks for files that have been removed from the object.
|
||||
*/
|
||||
function file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
// Check whether the field is defined on the object.
|
||||
if (!isset($entity->{$field['field_name']})) {
|
||||
// We cannot check for removed files if the field is not defined.
|
||||
return;
|
||||
}
|
||||
|
||||
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
|
||||
// On new revisions, all files are considered to be a new usage and no
|
||||
|
@@ -6,8 +6,8 @@ core = 7.x
|
||||
dependencies[] = field
|
||||
files[] = tests/file.test
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-05-08
|
||||
version = "7.28"
|
||||
; Information added by Drupal.org packaging script on 2015-04-02
|
||||
version = "7.36"
|
||||
project = "drupal"
|
||||
datestamp = "1399522731"
|
||||
datestamp = "1427943826"
|
||||
|
||||
|
@@ -357,6 +357,10 @@ function file_file_delete($file) {
|
||||
* support for a default value.
|
||||
*/
|
||||
function file_managed_file_process($element, &$form_state, $form) {
|
||||
// Append the '-upload' to the #id so the field label's 'for' attribute
|
||||
// corresponds with the file element.
|
||||
$original_id = $element['#id'];
|
||||
$element['#id'] .= '-upload';
|
||||
$fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0;
|
||||
|
||||
// Set some default element properties.
|
||||
@@ -366,7 +370,7 @@ function file_managed_file_process($element, &$form_state, $form) {
|
||||
|
||||
$ajax_settings = array(
|
||||
'path' => 'file/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
|
||||
'wrapper' => $element['#id'] . '-ajax-wrapper',
|
||||
'wrapper' => $original_id . '-ajax-wrapper',
|
||||
'effect' => 'fade',
|
||||
'progress' => array(
|
||||
'type' => $element['#progress_indicator'],
|
||||
@@ -461,13 +465,13 @@ function file_managed_file_process($element, &$form_state, $form) {
|
||||
$element['upload']['#attached']['js'] = array(
|
||||
array(
|
||||
'type' => 'setting',
|
||||
'data' => array('file' => array('elements' => array('#' . $element['#id'] . '-upload' => $extension_list)))
|
||||
'data' => array('file' => array('elements' => array('#' . $element['#id'] => $extension_list)))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Prefix and suffix used for Ajax replacement.
|
||||
$element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper">';
|
||||
$element['#prefix'] = '<div id="' . $original_id . '-ajax-wrapper">';
|
||||
$element['#suffix'] = '</div>';
|
||||
|
||||
return $element;
|
||||
@@ -478,6 +482,7 @@ function file_managed_file_process($element, &$form_state, $form) {
|
||||
*/
|
||||
function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL) {
|
||||
$fid = 0;
|
||||
$force_default = FALSE;
|
||||
|
||||
// Find the current value of this field from the form state.
|
||||
$form_state_fid = $form_state['values'];
|
||||
@@ -510,15 +515,35 @@ function file_managed_file_value(&$element, $input = FALSE, $form_state = NULL)
|
||||
$callback($element, $input, $form_state);
|
||||
}
|
||||
}
|
||||
// Load file if the FID has changed to confirm it exists.
|
||||
if (isset($input['fid']) && $file = file_load($input['fid'])) {
|
||||
$fid = $file->fid;
|
||||
// If a FID was submitted, load the file (and check access if it's not a
|
||||
// public file) to confirm it exists and that the current user has access
|
||||
// to it.
|
||||
if (isset($input['fid']) && ($file = file_load($input['fid']))) {
|
||||
// By default the public:// file scheme provided by Drupal core is the
|
||||
// only one that allows files to be publicly accessible to everyone, so
|
||||
// it is the only one for which the file access checks are bypassed.
|
||||
// Other modules which provide publicly accessible streams of their own
|
||||
// in hook_stream_wrappers() can add the corresponding scheme to the
|
||||
// 'file_public_schema' variable to bypass file access checks for those
|
||||
// as well. This should only be done for schemes that are completely
|
||||
// publicly accessible, with no download restrictions; for security
|
||||
// reasons all other schemes must go through the file_download_access()
|
||||
// check.
|
||||
if (in_array(file_uri_scheme($file->uri), variable_get('file_public_schema', array('public'))) || file_download_access($file->uri)) {
|
||||
$fid = $file->fid;
|
||||
}
|
||||
// If the current user doesn't have access, don't let the file be
|
||||
// changed.
|
||||
else {
|
||||
$force_default = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no input, set the default value.
|
||||
else {
|
||||
// If there is no input or if the default value was requested above, use the
|
||||
// default value.
|
||||
if ($input === FALSE || $force_default) {
|
||||
if ($element['#extended']) {
|
||||
$default_fid = isset($element['#default_value']['fid']) ? $element['#default_value']['fid'] : 0;
|
||||
$return = isset($element['#default_value']) ? $element['#default_value'] : array('fid' => 0);
|
||||
|
@@ -220,6 +220,128 @@ class FileFieldTestCase extends DrupalWebTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests adding a file to a non-node entity.
|
||||
*/
|
||||
class FileTaxonomyTermTestCase extends DrupalWebTestCase {
|
||||
protected $admin_user;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Taxonomy term file test',
|
||||
'description' => 'Tests adding a file to a non-node entity.',
|
||||
'group' => 'File',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
$modules[] = 'file';
|
||||
$modules[] = 'taxonomy';
|
||||
parent::setUp($modules);
|
||||
$this->admin_user = $this->drupalCreateUser(array('access content', 'access administration pages', 'administer site configuration', 'administer taxonomy'));
|
||||
$this->drupalLogin($this->admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file field and attaches it to the "Tags" taxonomy vocabulary.
|
||||
*
|
||||
* @param $name
|
||||
* The field name of the file field to create.
|
||||
* @param $uri_scheme
|
||||
* The URI scheme to use for the file field (for example, "private" to
|
||||
* create a field that stores private files or "public" to create a field
|
||||
* that stores public files).
|
||||
*/
|
||||
protected function createAttachFileField($name, $uri_scheme) {
|
||||
$field = array(
|
||||
'field_name' => $name,
|
||||
'type' => 'file',
|
||||
'settings' => array(
|
||||
'uri_scheme' => $uri_scheme,
|
||||
),
|
||||
'cardinality' => 1,
|
||||
);
|
||||
field_create_field($field);
|
||||
// Attach an instance of it.
|
||||
$instance = array(
|
||||
'field_name' => $name,
|
||||
'label' => 'File',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'tags',
|
||||
'required' => FALSE,
|
||||
'settings' => array(),
|
||||
'widget' => array(
|
||||
'type' => 'file_generic',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
field_create_instance($instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a public file can be attached to a taxonomy term.
|
||||
*
|
||||
* This is a regression test for https://www.drupal.org/node/2305017.
|
||||
*/
|
||||
public function testTermFilePublic() {
|
||||
$this->_testTermFile('public');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a private file can be attached to a taxonomy term.
|
||||
*
|
||||
* This is a regression test for https://www.drupal.org/node/2305017.
|
||||
*/
|
||||
public function testTermFilePrivate() {
|
||||
$this->_testTermFile('private');
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs tests for attaching a file field to a taxonomy term.
|
||||
*
|
||||
* @param $uri_scheme
|
||||
* The URI scheme to use for the file field, either "public" or "private".
|
||||
*/
|
||||
protected function _testTermFile($uri_scheme) {
|
||||
$field_name = strtolower($this->randomName());
|
||||
$this->createAttachFileField($field_name, $uri_scheme);
|
||||
// Get a file to upload.
|
||||
$file = current($this->drupalGetTestFiles('text'));
|
||||
// Add a filesize property to files as would be read by file_load().
|
||||
$file->filesize = filesize($file->uri);
|
||||
$langcode = LANGUAGE_NONE;
|
||||
$edit = array(
|
||||
"name" => $this->randomName(),
|
||||
);
|
||||
// Attach a file to the term.
|
||||
$edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($file->uri);
|
||||
$this->drupalPost("admin/structure/taxonomy/tags/add", $edit, t('Save'));
|
||||
// Find the term ID we just created.
|
||||
$tid = db_query_range('SELECT tid FROM {taxonomy_term_data} ORDER BY tid DESC', 0, 1)->fetchField();
|
||||
$terms = entity_load('taxonomy_term', array($tid));
|
||||
$term = $terms[$tid];
|
||||
$fid = $term->{$field_name}[LANGUAGE_NONE][0]['fid'];
|
||||
// Check that the uploaded file is present on the edit form.
|
||||
$this->drupalGet("taxonomy/term/$tid/edit");
|
||||
$file_input_name = $field_name . '[' . LANGUAGE_NONE . '][0][fid]';
|
||||
$this->assertFieldByXpath('//input[@type="hidden" and @name="' . $file_input_name . '"]', $fid, 'File is attached on edit form.');
|
||||
// Edit the term and change name without changing the file.
|
||||
$edit = array(
|
||||
"name" => $this->randomName(),
|
||||
);
|
||||
$this->drupalPost("taxonomy/term/$tid/edit", $edit, t('Save'));
|
||||
// Check that the uploaded file is still present on the edit form.
|
||||
$this->drupalGet("taxonomy/term/$tid/edit");
|
||||
$file_input_name = $field_name . '[' . LANGUAGE_NONE . '][0][fid]';
|
||||
$this->assertFieldByXpath('//input[@type="hidden" and @name="' . $file_input_name . '"]', $fid, 'File is attached on edit form.');
|
||||
// Load term while resetting the cache.
|
||||
$terms = entity_load('taxonomy_term', array($tid), array(), TRUE);
|
||||
$term = $terms[$tid];
|
||||
$this->assertTrue(!empty($term->{$field_name}[LANGUAGE_NONE]), 'Term has attached files.');
|
||||
$this->assertEqual($term->{$field_name}[LANGUAGE_NONE][0]['fid'], $fid, 'Same File ID is attached to the term.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the 'managed_file' element type.
|
||||
*
|
||||
@@ -352,6 +474,15 @@ class FileFieldWidgetTestCase extends FileFieldTestCase {
|
||||
$node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0];
|
||||
$this->assertFileExists($node_file, 'New file saved to disk on node creation.');
|
||||
|
||||
// Test that running field_attach_update() leaves the file intact.
|
||||
$field = new stdClass();
|
||||
$field->type = $type_name;
|
||||
$field->nid = $nid;
|
||||
field_attach_update('node', $field);
|
||||
$node = node_load($nid);
|
||||
$node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0];
|
||||
$this->assertFileExists($node_file, 'New file still saved to disk on field update.');
|
||||
|
||||
// Ensure the file can be downloaded.
|
||||
$this->drupalGet(file_create_url($node_file->uri));
|
||||
$this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.');
|
||||
@@ -755,6 +886,7 @@ class FileFieldDisplayTestCase extends FileFieldTestCase {
|
||||
$field_settings = array(
|
||||
'display_field' => '1',
|
||||
'display_default' => '1',
|
||||
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
||||
);
|
||||
$instance_settings = array(
|
||||
'description_field' => '1',
|
||||
@@ -795,6 +927,17 @@ class FileFieldDisplayTestCase extends FileFieldTestCase {
|
||||
|
||||
$this->assertNoRaw($default_output, 'Field is hidden when "display" option is unchecked.');
|
||||
|
||||
// Test that fields appear as expected during the preview.
|
||||
// Add a second file.
|
||||
$name = 'files[' . $field_name . '_' . LANGUAGE_NONE . '_1]';
|
||||
$edit[$name] = drupal_realpath($test_file->uri);
|
||||
|
||||
// Uncheck the display checkboxes and go to the preview.
|
||||
$edit[$field_name . '[' . LANGUAGE_NONE . '][0][display]'] = FALSE;
|
||||
$edit[$field_name . '[' . LANGUAGE_NONE . '][1][display]'] = FALSE;
|
||||
$this->drupalPost('node/' . $nid . '/edit', $edit, t('Preview'));
|
||||
$this->assertRaw($field_name . '[' . LANGUAGE_NONE . '][0][display]', 'First file appears as expected.');
|
||||
$this->assertRaw($field_name . '[' . LANGUAGE_NONE . '][1][display]', 'Second file appears as expected.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1167,5 +1310,18 @@ class FilePrivateTestCase extends FileFieldTestCase {
|
||||
// Ensure the file cannot be downloaded.
|
||||
$this->drupalGet(file_create_url($node_file->uri));
|
||||
$this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission.');
|
||||
|
||||
// Attempt to reuse the existing file when creating a new node, and confirm
|
||||
// that access is still denied.
|
||||
$edit = array();
|
||||
$edit['title'] = $this->randomName(8);
|
||||
$edit[$field_name . '[' . LANGUAGE_NONE . '][0][fid]'] = $node_file->fid;
|
||||
$this->drupalPost('node/add/page', $edit, t('Save'));
|
||||
$new_node = $this->drupalGetNodeByTitle($edit['title']);
|
||||
$this->assertTrue(!empty($new_node), 'Node was created.');
|
||||
$this->assertUrl('node/' . $new_node->nid);
|
||||
$this->assertNoRaw($node_file->filename, 'File without view field access permission does not appear after attempting to attach it to a new node.');
|
||||
$this->drupalGet(file_create_url($node_file->uri));
|
||||
$this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission after attempting to attach it to a new node.');
|
||||
}
|
||||
}
|
||||
|
@@ -5,8 +5,8 @@ version = VERSION
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-05-08
|
||||
version = "7.28"
|
||||
; Information added by Drupal.org packaging script on 2015-04-02
|
||||
version = "7.36"
|
||||
project = "drupal"
|
||||
datestamp = "1399522731"
|
||||
datestamp = "1427943826"
|
||||
|
||||
|
Reference in New Issue
Block a user