upgrades core to 8.4.2

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-14 16:09:54 +01:00
parent bd60eff9b3
commit c2b4e25be4
3504 changed files with 140306 additions and 38684 deletions
@@ -2,61 +2,9 @@
namespace Drupal\quickedit\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Access check for editing entity fields.
* @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0.
*/
class EditEntityFieldAccessCheck implements AccessInterface, EditEntityFieldAccessCheckInterface {
/**
* Checks Quick Edit access to the field.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity containing the field.
* @param string $field_name
* The field name.
* @param string $langcode
* The langcode.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*
* @todo Use the $account argument: https://www.drupal.org/node/2266809.
*/
public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) {
if (!$this->validateRequestAttributes($entity, $field_name, $langcode)) {
return AccessResult::forbidden();
}
return $this->accessEditEntityField($entity, $field_name);
}
/**
* {@inheritdoc}
*/
public function accessEditEntityField(EntityInterface $entity, $field_name) {
return $entity->access('update', NULL, TRUE)->andIf($entity->get($field_name)->access('edit', NULL, TRUE));
}
/**
* Validates request attributes.
*/
protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode) {
// Validate the field name and language.
if (!$field_name || !$entity->hasField($field_name)) {
return FALSE;
}
if (!$langcode || !$entity->hasTranslation($langcode)) {
return FALSE;
}
return TRUE;
}
class EditEntityFieldAccessCheck extends QuickEditEntityFieldAccessCheck {
}
@@ -2,24 +2,9 @@
namespace Drupal\quickedit\Access;
use Drupal\Core\Entity\EntityInterface;
/**
* Access check for editing entity fields.
* @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0.
*/
interface EditEntityFieldAccessCheckInterface {
/**
* Checks access to edit the requested field of the requested entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
* @param string $field_name
* The field name.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function accessEditEntityField(EntityInterface $entity, $field_name);
interface EditEntityFieldAccessCheckInterface extends QuickEditEntityFieldAccessCheckInterface {
}
@@ -0,0 +1,62 @@
<?php
namespace Drupal\quickedit\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Access check for in-place editing entity fields.
*/
class QuickEditEntityFieldAccessCheck implements AccessInterface, QuickEditEntityFieldAccessCheckInterface {
/**
* Checks Quick Edit access to the field.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity containing the field.
* @param string $field_name
* The field name.
* @param string $langcode
* The langcode.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*
* @todo Use the $account argument: https://www.drupal.org/node/2266809.
*/
public function access(EntityInterface $entity, $field_name, $langcode, AccountInterface $account) {
if (!$this->validateRequestAttributes($entity, $field_name, $langcode)) {
return AccessResult::forbidden();
}
return $this->accessEditEntityField($entity, $field_name);
}
/**
* {@inheritdoc}
*/
public function accessEditEntityField(EntityInterface $entity, $field_name) {
return $entity->access('update', NULL, TRUE)->andIf($entity->get($field_name)->access('edit', NULL, TRUE));
}
/**
* Validates request attributes.
*/
protected function validateRequestAttributes(EntityInterface $entity, $field_name, $langcode) {
// Validate the field name and language.
if (!$field_name || !$entity->hasField($field_name)) {
return FALSE;
}
if (!$langcode || !$entity->hasTranslation($langcode)) {
return FALSE;
}
return TRUE;
}
}
@@ -0,0 +1,25 @@
<?php
namespace Drupal\quickedit\Access;
use Drupal\Core\Entity\EntityInterface;
/**
* Access check for in-place editing entity fields.
*/
interface QuickEditEntityFieldAccessCheckInterface {
/**
* Checks access to edit the requested field of the requested entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
* @param string $field_name
* The field name.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function accessEditEntityField(EntityInterface $entity, $field_name);
}
@@ -5,7 +5,7 @@ namespace Drupal\quickedit;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface;
use Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
/**
@@ -16,7 +16,7 @@ class MetadataGenerator implements MetadataGeneratorInterface {
/**
* An object that checks if a user has access to edit a given entity field.
*
* @var \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface
* @var \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface
*/
protected $accessChecker;
@@ -37,14 +37,14 @@ class MetadataGenerator implements MetadataGeneratorInterface {
/**
* Constructs a new MetadataGenerator.
*
* @param \Drupal\quickedit\Access\EditEntityFieldAccessCheckInterface $access_checker
* @param \Drupal\quickedit\Access\QuickEditEntityFieldAccessCheckInterface $access_checker
* An object that checks if a user has access to edit a given field.
* @param \Drupal\quickedit\EditorSelectorInterface $editor_selector
* An object that determines which editor to attach to a given field.
* @param \Drupal\Component\Plugin\PluginManagerInterface $editor_manager
* The manager for editor plugins.
*/
public function __construct(EditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) {
public function __construct(QuickEditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) {
$this->accessChecker = $access_checker;
$this->editorSelector = $editor_selector;
$this->editorManager = $editor_manager;
@@ -42,6 +42,13 @@ class QuickEditLoadingTest extends WebTestBase {
*/
protected $authorUser;
/**
* A test node.
*
* @var \Drupal\node\NodeInterface
*/
protected $testNode;
/**
* A author user with permissions to access in-place editor.
*
@@ -74,7 +81,7 @@ class QuickEditLoadingTest extends WebTestBase {
$node_type->save();
// Create one node of the above node type using the above text format.
$this->drupalCreateNode([
$this->testNode = $this->drupalCreateNode([
'type' => 'article',
'body' => [
0 => [
@@ -115,12 +122,12 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertIdentical(Json::encode(['message' => "The 'access in-place editing' permission is required."]), $response);
$this->assertResponse(403);
// Quick Edit's JavaScript would SearchRankingTestnever hit these endpoints if the metadata
// Quick Edit's JavaScript would never hit these endpoints if the metadata
// was empty as above, but we need to make sure that malicious users aren't
// able to use any of the other endpoints either.
$post = ['editors[0]' => 'form'] + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/attachments', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$message = Json::encode(['message' => "A fatal error occurred: The 'access in-place editing' permission is required."]);
$message = Json::encode(['message' => "The 'access in-place editing' permission is required."]);
$this->assertIdentical($message, $response);
$this->assertResponse(403);
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
@@ -317,6 +324,26 @@ class QuickEditLoadingTest extends WebTestBase {
}
}
/**
* Test quickedit does not appear for entities with pending revisions.
*/
public function testWithPendingRevision() {
$this->drupalLogin($this->editorUser);
$this->drupalGet('node/' . $this->testNode->id());
$this->assertRaw('data-quickedit-entity-id="node/' . $this->testNode->id() . '"');
$this->assertRaw('data-quickedit-field-id="node/' . $this->testNode->id() . '/title/' . $this->testNode->language()->getId() . '/full"');
$this->testNode->title = 'Updated node';
$this->testNode->setNewRevision(TRUE);
$this->testNode->isDefaultRevision(FALSE);
$this->testNode->save();
$this->drupalGet('node/' . $this->testNode->id());
$this->assertNoRaw('data-quickedit-entity-id="node/' . $this->testNode->id() . '"');
$this->assertNoRaw('data-quickedit-field-id="node/' . $this->testNode->id() . '/title/' . $this->testNode->language()->getId() . '/full"');
}
/**
* Tests the loading of Quick Edit for the title base field.
*/