Skip to content
Commits on Source (11)
...@@ -81,7 +81,7 @@ class Drupal { ...@@ -81,7 +81,7 @@ class Drupal {
/** /**
* The current system version. * The current system version.
*/ */
const VERSION = '8.1.9-dev'; const VERSION = '8.1.11-dev';
/** /**
* Core API compatibility. * Core API compatibility.
......
...@@ -188,13 +188,16 @@ public function onException(GetResponseForExceptionEvent $event) { ...@@ -188,13 +188,16 @@ public function onException(GetResponseForExceptionEvent $event) {
if (!method_exists($this, $method)) { if (!method_exists($this, $method)) {
if ($exception instanceof HttpExceptionInterface) { if ($exception instanceof HttpExceptionInterface) {
$this->onFormatUnknown($event); $this->onFormatUnknown($event);
$response = $event->getResponse();
$response->headers->set('Content-Type', 'text/plain');
} }
else { else {
$this->onHtml($event); $this->onHtml($event);
} }
return;
} }
$this->$method($event); else {
$this->$method($event);
}
} }
/** /**
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
namespace Drupal\comment; namespace Drupal\comment;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldItemList; use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Session\AccountInterface;
/** /**
* Defines a item list class for comment fields. * Defines a item list class for comment fields.
...@@ -37,4 +39,28 @@ public function offsetExists($offset) { ...@@ -37,4 +39,28 @@ public function offsetExists($offset) {
return parent::offsetExists($offset); return parent::offsetExists($offset);
} }
/**
* {@inheritdoc}
*/
public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($operation === 'edit') {
// Only users with administer comments permission can edit the comment
// status field.
$result = AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'administer comments');
return $return_as_object ? $result : $result->isAllowed();
}
if ($operation === 'view') {
// Only users with either post comments or access comments permisison can
// view the field value. The formatter,
// Drupal\comment\Plugin\Field\FieldFormatter\CommentDefaultFormatter,
// takes care of showing the thread and form based on individual
// permissions, so if a user only has ‘post comments’ access, only the
// form will be shown and not the comments.
$result = AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'access comments')
->orIf(AccessResult::allowedIfHasPermission($account ?: \Drupal::currentUser(), 'post comments'));
return $return_as_object ? $result : $result->isAllowed();
}
return parent::access($operation, $account, $return_as_object);
}
} }
...@@ -384,6 +384,7 @@ function testCommentFunctionality() { ...@@ -384,6 +384,7 @@ function testCommentFunctionality() {
'administer entity_test fields', 'administer entity_test fields',
'view test entity', 'view test entity',
'administer entity_test content', 'administer entity_test content',
'administer comments',
)); ));
$this->drupalLogin($limited_user); $this->drupalLogin($limited_user);
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment'); $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
......
<?php
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
/**
* Tests comment status field access.
*
* @group comment
*/
class CommentStatusFieldAccessTest extends BrowserTestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
public $profile = 'testing';
/**
* Comment admin.
*
* @var \Drupal\user\UserInterface
*/
protected $commentAdmin;
/**
* Node author.
*
* @var \Drupal\user\UserInterface
*/
protected $nodeAuthor;
/**
* {@inheritdoc}
*/
public static $modules = [
'node',
'comment',
'user',
'system',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$node_type = NodeType::create([
'type' => 'article',
'name' => t('Article'),
]);
$node_type->save();
$this->nodeAuthor = $this->drupalCreateUser([
'create article content',
'skip comment approval',
'post comments',
'edit own comments',
'access comments',
'administer nodes',
]);
$this->commentAdmin = $this->drupalCreateUser([
'administer comments',
'create article content',
'edit own comments',
'skip comment approval',
'post comments',
'access comments',
'administer nodes',
]);
$this->addDefaultCommentField('node', 'article');
}
/**
* Tests comment status field access.
*/
public function testCommentStatusFieldAccessStatus() {
$this->drupalLogin($this->nodeAuthor);
$this->drupalGet('node/add/article');
$assert = $this->assertSession();
$assert->fieldNotExists('comment[0][status]');
$this->submitForm([
'title[0][value]' => 'Node 1',
], t('Save and publish'));
$assert->fieldExists('subject[0][value]');
$this->drupalLogin($this->commentAdmin);
$this->drupalGet('node/add/article');
$assert->fieldExists('comment[0][status]');
$this->submitForm([
'title[0][value]' => 'Node 2',
], t('Save and publish'));
$assert->fieldExists('subject[0][value]');
}
}
...@@ -65,14 +65,17 @@ function config_file_download($uri) { ...@@ -65,14 +65,17 @@ function config_file_download($uri) {
$scheme = file_uri_scheme($uri); $scheme = file_uri_scheme($uri);
$target = file_uri_target($uri); $target = file_uri_target($uri);
if ($scheme == 'temporary' && $target == 'config.tar.gz') { if ($scheme == 'temporary' && $target == 'config.tar.gz') {
$request = \Drupal::request(); if (\Drupal::currentUser()->hasPermission('export configuration')) {
$date = DateTime::createFromFormat('U', $request->server->get('REQUEST_TIME')); $request = \Drupal::request();
$date_string = $date->format('Y-m-d-H-i'); $date = DateTime::createFromFormat('U', $request->server->get('REQUEST_TIME'));
$hostname = str_replace('.', '-', $request->getHttpHost()); $date_string = $date->format('Y-m-d-H-i');
$filename = 'config' . '-' . $hostname . '-' . $date_string . '.tar.gz'; $hostname = str_replace('.', '-', $request->getHttpHost());
$disposition = 'attachment; filename="' . $filename . '"'; $filename = 'config' . '-' . $hostname . '-' . $date_string . '.tar.gz';
return array( $disposition = 'attachment; filename="' . $filename . '"';
'Content-disposition' => $disposition, return array(
); 'Content-disposition' => $disposition,
);
}
return -1;
} }
} }
...@@ -88,6 +88,12 @@ function testExport() { ...@@ -88,6 +88,12 @@ function testExport() {
// Check the single export form doesn't have "form-required" elements. // Check the single export form doesn't have "form-required" elements.
$this->drupalGet('admin/config/development/configuration/single/export'); $this->drupalGet('admin/config/development/configuration/single/export');
$this->assertNoRaw('js-form-required form-required', 'No form required fields are found.'); $this->assertNoRaw('js-form-required form-required', 'No form required fields are found.');
// Ensure the temporary file is not available to users without the
// permission.
$this->drupalLogout();
$this->drupalGet('system/temporary', ['query' => ['file' => 'config.tar.gz']]);
$this->assertResponse(403);
} }
} }
...@@ -81,9 +81,11 @@ public function delete() { ...@@ -81,9 +81,11 @@ public function delete() {
parent::delete(); parent::delete();
$entity = $this->getEntity(); $entity = $this->getEntity();
// Delete all file usages within this entity. // If a translation is deleted only decrement the file usage by one. If the
// default translation is deleted remove all file usages within this entity.
$count = $entity->isDefaultTranslation() ? 0 : 1;
foreach ($this->referencedEntities() as $file) { foreach ($this->referencedEntities() as $file) {
\Drupal::service('file.usage')->delete($file, 'file', $entity->getEntityTypeId(), $entity->id(), 0); \Drupal::service('file.usage')->delete($file, 'file', $entity->getEntityTypeId(), $entity->id(), $count);
} }
} }
......
...@@ -2,6 +2,13 @@ ...@@ -2,6 +2,13 @@
namespace Drupal\Tests\file\Kernel; namespace Drupal\Tests\file\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/** /**
* Tests file usage functions. * Tests file usage functions.
* *
...@@ -203,4 +210,57 @@ function testTempFileCustomCleanup() { ...@@ -203,4 +210,57 @@ function testTempFileCustomCleanup() {
$this->assertTrue(file_exists($perm_new->getFileUri()), 'New permanent file was correctly ignored.'); $this->assertTrue(file_exists($perm_new->getFileUri()), 'New permanent file was correctly ignored.');
} }
/**
* Tests file usage with translated entities.
*/
public function testFileUsageWithEntityTranslation() {
/** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
$file_usage = $this->container->get('file.usage');
$this->enableModules(['node', 'language']);
$this->installEntitySchema('node');
$this->installSchema('node', ['node_access']);
// Activate English and Romanian languages.
ConfigurableLanguage::create(['id' => 'en'])->save();
ConfigurableLanguage::create(['id' => 'ro'])->save();
NodeType::create(['type' => 'page'])->save();
ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
->setLanguageAlterable(FALSE)
->setDefaultLangcode('en')
->save();
// Create a file field attached to 'page' node-type.
FieldStorageConfig::create([
'type' => 'file',
'entity_type' => 'node',
'field_name' => 'file',
])->save();
FieldConfig::create([
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => 'file',
'label' => 'File',
])->save();
// Create a node, attach a file and add a Romanian translation.
$node = Node::create(['type' => 'page', 'title' => 'Page']);
$node
->set('file', $file = $this->createFile())
->addTranslation('ro', $node->getTranslation('en')->toArray())
->save();
// Check that the file is used twice.
$usage = $file_usage->listUsage($file);
$this->assertEquals(2, $usage['file']['node'][$node->id()]);
// Remove the Romanian translation.
$node->removeTranslation('ro');
$node->save();
// Check that one usage has been removed and is used only once now.
$usage = $file_usage->listUsage($file);
$this->assertEquals(1, $usage['file']['node'][$node->id()]);
}
} }
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
* arguments can be passed to the callback as this would make the migration YAML * arguments can be passed to the callback as this would make the migration YAML
* file too complex. * file too complex.
* *
* @link https://www.drupal.org/node/2181783 Online handbook documentation for callback process plugin @endlink
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "callback" * id = "callback"
* ) * )
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
/** /**
* Concatenates the strings in the current value. * Concatenates the strings in the current value.
* *
* @link https://www.drupal.org/node/2345927 Online handbook documentation for concat process plugin @endlink
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "concat", * id = "concat",
* handle_multiples = TRUE * handle_multiples = TRUE
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
* creating filter format names, the current value is checked against the * creating filter format names, the current value is checked against the
* existing filter format names and if it exists, a numeric postfix is added * existing filter format names and if it exists, a numeric postfix is added
* and incremented until a unique value is created. * and incremented until a unique value is created.
*
* @link https://www.drupal.org/node/2345929 Online handbook documentation for dedupebase process plugin @endlink
*/ */
abstract class DedupeBase extends ProcessPluginBase { abstract class DedupeBase extends ProcessPluginBase {
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
/** /**
* Ensures value is not duplicated against an entity field. * Ensures value is not duplicated against an entity field.
* *
* @link https://www.drupal.org/node/2135325 Online handbook documentation for dedupe_entity process plugin @endlink
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "dedupe_entity" * id = "dedupe_entity"
* ) * )
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
/** /**
* This plugin sets missing values on the destination. * This plugin sets missing values on the destination.
* *
* @link https://www.drupal.org/node/2135313 Online handbook documentation for default_value process plugin @endlink
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "default_value" * id = "default_value"
* ) * )
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
/** /**
* This plugin explodes a delimited string into an array of values. * This plugin explodes a delimited string into an array of values.
* *
* @link https://www.drupal.org/node/2674504 Online handbook documentation for explode process plugin @endlink
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "explode" * id = "explode"
* ) * )
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
/** /**
* This plugin extracts a value from an array. * This plugin extracts a value from an array.
* *
* @see https://www.drupal.org/node/2152731 * @link https://www.drupal.org/node/2152731 Online handbook documentation for extract process plugin @endlink
* *
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "extract" * id = "extract"
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* once a single value gets transformed into multiple values. This plugin will * once a single value gets transformed into multiple values. This plugin will
* flatten them back down to single values again. * flatten them back down to single values again.
* *
* @see https://www.drupal.org/node/2154215 * @link https://www.drupal.org/node/2154215 Online handbook documentation for flatten process plugin @endlink
* *
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "flatten", * id = "flatten",
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
/** /**
* This plugin copies from the source to the destination. * This plugin copies from the source to the destination.
* *
* @link https://www.drupal.org/node/2135307 Online handbook documentation for get process plugin @endlink
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "get" * id = "get"
* ) * )
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/** /**
* This plugin iterates and processes an array. * This plugin iterates and processes an array.
* *
* @see https://www.drupal.org/node/2135345 * @link https://www.drupal.org/node/2135345 Online handbook documentation for iterator process plugin @endlink
* *
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "iterator", * id = "iterator",
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
* and replaced by an underscore and multiple underscores are collapsed into * and replaced by an underscore and multiple underscores are collapsed into
* one. * one.
* *
* @link https://www.drupal.org/node/2135323 Online handbook documentation for machine_name process plugin @endlink
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "machine_name" * id = "machine_name"
* ) * )
......