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

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -2,8 +2,6 @@ quickedit.metadata:
path: '/quickedit/metadata'
defaults:
_controller: '\Drupal\quickedit\QuickEditController::metadata'
options:
_theme: ajax_base_page
requirements:
_permission: 'access in-place editing'
@ -19,7 +17,6 @@ quickedit.field_form:
defaults:
_controller: '\Drupal\quickedit\QuickEditController::fieldForm'
options:
_theme: ajax_base_page
parameters:
entity:
type: entity:{entity_type}

View file

@ -27,14 +27,6 @@ class InPlaceEditor extends Plugin {
*/
public $id;
/**
* An array of in-place editors plugin IDs that have registered themselves as
* alternatives to this in-place editor.
*
* @var array
*/
public $alternativeTo;
/**
* The name of the module providing the in-place editor plugin.
*

View file

@ -36,9 +36,9 @@ class EditorSelector implements EditorSelectorInterface {
/**
* Constructs a new EditorSelector.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface
* @param \Drupal\Component\Plugin\PluginManagerInterface $editor_manager
* The manager for editor plugins.
* @param \Drupal\Core\Field\FormatterPluginManager
* @param \Drupal\Core\Field\FormatterPluginManager $formatter_manager
* The manager for formatter plugins.
*/
public function __construct(PluginManagerInterface $editor_manager, FormatterPluginManager $formatter_manager) {
@ -50,21 +50,8 @@ class EditorSelector implements EditorSelectorInterface {
* {@inheritdoc}
*/
public function getEditor($formatter_type, FieldItemListInterface $items) {
// Build a static cache of the editors that have registered themselves as
// alternatives to a certain editor.
if (!isset($this->alternatives)) {
$editors = $this->editorManager->getDefinitions();
foreach ($editors as $alternative_editor_id => $editor) {
if (isset($editor['alternativeTo'])) {
foreach ($editor['alternativeTo'] as $original_editor_id) {
$this->alternatives[$original_editor_id][] = $alternative_editor_id;
}
}
}
}
// Check if the formatter defines an appropriate in-place editor. For
// example, text formatters displaying untrimmed text can choose to use the
// example, text formatters displaying plain text can choose to use the
// 'plain_text' editor. If the formatter doesn't specify, fall back to the
// 'form' editor, since that can work for any field. Formatter definitions
// can use 'disabled' to explicitly opt out of in-place editing.

View file

@ -41,7 +41,7 @@ class MetadataGenerator implements MetadataGeneratorInterface {
* 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
* @param \Drupal\Component\Plugin\PluginManagerInterface $editor_manager
* The manager for editor plugins.
*/
public function __construct(EditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) {

View file

@ -21,16 +21,7 @@ class PlainTextEditor extends InPlaceEditorBase {
$field_definition = $items->getFieldDefinition();
// This editor is incompatible with multivalued fields.
if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
return FALSE;
}
// This editor is incompatible with formatted ("rich") text fields.
elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) {
return FALSE;
}
else {
return TRUE;
}
return $field_definition->getFieldStorageDefinition()->getCardinality() == 1;
}
/**

View file

@ -3,6 +3,7 @@
namespace Drupal\quickedit\Tests;
use Drupal\Component\Serialization\Json;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
@ -130,7 +131,7 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
$quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->fieldName . '/' . $this->node->language()->getId() . '/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for
@ -148,7 +149,7 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
);
// Submit field form and check response. Should render back all the terms.
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->setRawContent($ajax_commands[0]['data']);
@ -161,7 +162,7 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
// PrivateTempStore.
$quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->fieldName . '/' . $this->node->language()->getId() . '/full';
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response);
// The AjaxResponse's first command is an InsertCommand which contains

View file

@ -67,6 +67,12 @@ class QuickEditLoadingTest extends WebTestBase {
'name' => 'Article',
));
// Set the node type to initially not have revisions.
// Testing with revisions will be done later.
$node_type = NodeType::load('article');
$node_type->setNewRevision(FALSE);
$node_type->save();
// Create one node of the above node type using the above text format.
$this->drupalCreateNode(array(
'type' => 'article',
@ -182,7 +188,7 @@ class QuickEditLoadingTest extends WebTestBase {
// 1. a settings command with useless metadata: AjaxController is dumb
// 2. an insert command that loads the required in-place editors
$post = array('editors[0]' => 'form') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/attachments', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/attachments', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response);
$this->assertIdentical(2, count($ajax_commands), 'The attachments HTTP request results in two AJAX commands.');
// First command: settings.
@ -194,7 +200,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Retrieving the form for this field should result in a 200 response,
// containing only a quickeditFieldForm command.
$post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
@ -222,7 +228,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Submit field form and check response. This should store the updated
// entity in PrivateTempStore on the server.
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
@ -264,7 +270,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Retrieve field form.
$post = array('nocssjs' => 'true', 'reset' => 'true');
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
@ -281,7 +287,7 @@ class QuickEditLoadingTest extends WebTestBase {
'form_build_id' => $build_id_match[1],
);
$post += $edit + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
@ -339,7 +345,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Retrieving the form for this field should result in a 200 response,
// containing only a quickeditFieldForm command.
$post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
@ -366,7 +372,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Submit field form and check response. This should store the
// updated entity in PrivateTempStore on the server.
$response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/title/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
@ -418,7 +424,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Request editing to render results with the custom render pipeline.
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($custom_render_url, 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost($custom_render_url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response);
// Prepare form values for submission. drupalPostAJAX() is not suitable for
@ -442,7 +448,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Submit field form and check response. Should render with the custom
// render pipeline.
$response = $this->drupalPost($custom_render_url, 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost($custom_render_url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.');
@ -462,7 +468,7 @@ class QuickEditLoadingTest extends WebTestBase {
$this->drupalLogin($this->editorUser);
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
@ -490,7 +496,7 @@ class QuickEditLoadingTest extends WebTestBase {
// Submit field form and check response. Should throw a validation error
// because the node was changed in the meantime.
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post);
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical(2, count($ajax_commands), 'The field form HTTP request results in two AJAX commands.');
@ -554,7 +560,7 @@ class QuickEditLoadingTest extends WebTestBase {
], t('Save'));
// The image field form should load normally.
$response = $this->drupalPost('quickedit/form/node/1/field_image/en/full', 'application/vnd.drupal-ajax', ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData());
$response = $this->drupalPost('quickedit/form/node/1/field_image/en/full', '', ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData(), ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
$this->assertIdentical('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The quickeditFieldForm command contains a form.');

View file

@ -18,3 +18,16 @@ function quickedit_test_quickedit_render_field(EntityInterface $entity, $field_n
'#suffix' => '</div>',
);
}
/**
* Implements hook_field_formatter_info_alter().
*
* @see quickedit_field_formatter_info_alter()
* @see editor_field_formatter_info_alter()
*/
function quickedit_test_field_formatter_info_alter(&$info) {
// Update \Drupal\text\Plugin\Field\FieldFormatter\TextDefaultFormatter's
// annotation to indicate that it supports the 'wysiwyg' in-place editor
// provided by this module.
$info['text_default']['quickedit'] = ['editor' => 'wysiwyg'];
}

View file

@ -10,7 +10,6 @@ use Drupal\quickedit\Plugin\InPlaceEditorBase;
*
* @InPlaceEditor(
* id = "wysiwyg",
* alternativeTo = {"plain_text"}
* )
*/
class WysiwygEditor extends InPlaceEditorBase {
@ -28,12 +27,7 @@ class WysiwygEditor extends InPlaceEditorBase {
// This editor is compatible with formatted ("rich") text fields; but only
// if there is a currently active text format and that text format is the
// 'full_html' text format.
elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) {
if ($items[0]->format === 'full_html') {
return TRUE;
}
return FALSE;
}
return $items[0]->format === 'full_html';
}
/**

View file

@ -37,7 +37,9 @@ class EditorSelectionTest extends QuickEditTestBase {
* Returns the in-place editor that Quick Edit selects.
*/
protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default') {
$entity = entity_load('entity_test', $entity_id, TRUE);
$storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
$storage->resetCache([$entity_id]);
$entity = $storage->load($entity_id);
$items = $entity->get($field_name);
$options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name);
return $this->editorSelector->getEditor($options['type'], $items);

View file

@ -93,7 +93,7 @@ class MetadataGeneratorTest extends QuickEditTestBase {
$entity->{$field_1_name}->value = 'Test';
$entity->{$field_2_name}->value = 42;
$entity->save();
$entity = entity_load('entity_test', $entity->id());
$entity = EntityTest::load($entity->id());
// Verify metadata for field 1.
$items_1 = $entity->get($field_1_name);
@ -159,7 +159,7 @@ class MetadataGeneratorTest extends QuickEditTestBase {
$entity->{$field_name}->value = 'Test';
$entity->{$field_name}->format = 'full_html';
$entity->save();
$entity = entity_load('entity_test', $entity->id());
$entity = EntityTest::load($entity->id());
// Verify metadata.
$items = $entity->get($field_name);