updated core and modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-09-09 16:27:51 +02:00
parent 027aa99b32
commit 41863f872c
7810 changed files with 318922 additions and 83631 deletions
@@ -27,7 +27,7 @@ class FieldFormSavedCommand extends BaseCommand {
* The same re-rendered edited field, but in different view modes, for other
* instances of the same field on the user's page. Keyed by view mode.
*/
public function __construct($data, $other_view_modes = array()) {
public function __construct($data, $other_view_modes = []) {
parent::__construct('quickeditFieldFormSaved', $data);
$this->other_view_modes = $other_view_modes;
@@ -37,11 +37,11 @@ class FieldFormSavedCommand extends BaseCommand {
* {@inheritdoc}
*/
public function render() {
return array(
return [
'command' => $this->command,
'data' => $this->data,
'other_view_modes' => $this->other_view_modes,
);
];
}
}
@@ -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.
*
+5 -18
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.
@@ -78,7 +65,7 @@ class EditorSelector implements EditorSelectorInterface {
}
// No early return, so create a list of all choices.
$editor_choices = array($editor_id);
$editor_choices = [$editor_id];
if (isset($this->alternatives[$editor_id])) {
$editor_choices = array_merge($editor_choices, $this->alternatives[$editor_id]);
}
@@ -99,7 +86,7 @@ class EditorSelector implements EditorSelectorInterface {
* {@inheritdoc}
*/
public function getEditorAttachments(array $editor_ids) {
$attachments = array();
$attachments = [];
$editor_ids = array_unique($editor_ids);
// Editor plugins' attachments.
@@ -100,19 +100,19 @@ class QuickEditFieldForm extends FormBase {
// Add a dummy changed timestamp field to attach form errors to.
if ($entity instanceof EntityChangedInterface) {
$form['changed_field'] = array(
$form['changed_field'] = [
'#type' => 'hidden',
'#value' => $entity->getChangedTime(),
);
];
}
// Add a submit button. Give it a class for easy JavaScript targeting.
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
'#attributes' => array('class' => array('quickedit-form-submit')),
);
'#attributes' => ['class' => ['quickedit-form-submit']],
];
// Simplify it for optimal in-place use.
$this->simplify($form, $form_state);
@@ -183,7 +183,7 @@ class QuickEditFieldForm extends FormBase {
// @todo Refine automated log messages and abstract them to all entity
// types: https://www.drupal.org/node/1678002.
if ($entity->getEntityTypeId() == 'node' && $entity->isNewRevision() && $entity->revision_log->isEmpty()) {
$entity->revision_log = t('Updated the %field-name field through in-place editing.', array('%field-name' => $entity->get($field_name)->getFieldDefinition()->getLabel()));
$entity->revision_log = t('Updated the %field-name field through in-place editing.', ['%field-name' => $entity->get($field_name)->getFieldDefinition()->getLabel()]);
}
return $entity;
@@ -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) {
@@ -54,9 +54,9 @@ class MetadataGenerator implements MetadataGeneratorInterface {
* {@inheritdoc}
*/
public function generateEntityMetadata(EntityInterface $entity) {
return array(
return [
'label' => $entity->label(),
);
];
}
/**
@@ -69,24 +69,24 @@ class MetadataGenerator implements MetadataGeneratorInterface {
// Early-return if user does not have access.
$access = $this->accessChecker->accessEditEntityField($entity, $field_name);
if (!$access) {
return array('access' => FALSE);
return ['access' => FALSE];
}
// Early-return if no editor is available.
$formatter_id = EntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getRenderer($field_name)->getPluginId();
$editor_id = $this->editorSelector->getEditor($formatter_id, $items);
if (!isset($editor_id)) {
return array('access' => FALSE);
return ['access' => FALSE];
}
// Gather metadata, allow the editor to add additional metadata of its own.
$label = $items->getFieldDefinition()->getLabel();
$editor = $this->editorManager->createInstance($editor_id);
$metadata = array(
$metadata = [
'label' => $label,
'access' => TRUE,
'editor' => $editor_id,
);
];
$custom_metadata = $editor->getMetadata($items);
if (count($custom_metadata)) {
$metadata['custom'] = $custom_metadata;
@@ -25,11 +25,11 @@ class FormEditor extends InPlaceEditorBase {
* {@inheritdoc}
*/
public function getAttachments() {
return array(
'library' => array(
return [
'library' => [
'quickedit/quickedit.inPlaceEditor.form',
),
);
],
];
}
}
@@ -21,27 +21,18 @@ 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;
}
/**
* {@inheritdoc}
*/
public function getAttachments() {
return array(
'library' => array(
return [
'library' => [
'quickedit/quickedit.inPlaceEditor.plainText',
),
);
],
];
}
}
@@ -18,8 +18,8 @@ abstract class InPlaceEditorBase extends PluginBase implements InPlaceEditorInte
/**
* {@inheritdoc}
*/
function getMetadata(FieldItemListInterface $items) {
return array();
public function getMetadata(FieldItemListInterface $items) {
return [];
}
}
@@ -98,7 +98,7 @@ class QuickEditController extends ControllerBase {
}
$entities = $request->request->get('entities');
$metadata = array();
$metadata = [];
foreach ($fields as $field) {
list($entity_type, $entity_id, $field_name, $langcode, $view_mode) = explode('/', $field);
@@ -205,7 +205,7 @@ class QuickEditController extends ControllerBase {
// Re-render the updated field for other view modes (i.e. for other
// instances of the same logical field on the user's page).
$other_view_mode_ids = $request->request->get('other_view_modes') ?: array();
$other_view_mode_ids = $request->request->get('other_view_modes') ?: [];
$other_view_modes = array_map($render_field_in_view_mode, array_combine($other_view_mode_ids, $other_view_mode_ids));
$response->addCommand(new FieldFormSavedCommand($output, $other_view_modes));
@@ -220,9 +220,9 @@ class QuickEditController extends ControllerBase {
$errors = $form_state->getErrors();
if (count($errors)) {
$status_messages = array(
$status_messages = [
'#type' => 'status_messages'
);
];
$response->addCommand(new FieldFormValidationErrorsCommand($this->renderer->renderRoot($status_messages)));
}
}
@@ -266,7 +266,7 @@ class QuickEditController extends ControllerBase {
// by a dash; the first part must be the module name.
$mode_id_parts = explode('-', $view_mode_id, 2);
$module = reset($mode_id_parts);
$args = array($entity, $field_name, $view_mode_id, $langcode);
$args = [$entity, $field_name, $view_mode_id, $langcode];
$output = $this->moduleHandler()->invoke($module, 'quickedit_render_field', $args);
}
@@ -291,10 +291,10 @@ class QuickEditController extends ControllerBase {
// Return information about the entity that allows a front end application
// to identify it.
$output = array(
$output = [
'entity_type' => $entity->getEntityTypeId(),
'entity_id' => $entity->id()
);
];
// Respond to client that the entity was saved properly.
$response = new AjaxResponse();
@@ -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;
@@ -24,7 +25,7 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('node', 'taxonomy', 'quickedit');
public static $modules = ['node', 'taxonomy', 'quickedit'];
/**
* Stores the node used for the tests.
@@ -71,9 +72,9 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(array(
$this->drupalCreateContentType([
'type' => 'article',
));
]);
// Create the vocabulary for the tag field.
$this->vocabulary = Vocabulary::create([
'name' => 'quickedit testing tags',
@@ -82,12 +83,12 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
$this->vocabulary->save();
$this->fieldName = 'field_' . $this->vocabulary->id();
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $this->fieldName, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
@@ -113,7 +114,7 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
$this->term1 = $this->createTerm();
$this->term2 = $this->createTerm();
$node = array();
$node = [];
$node['type'] = 'article';
$node[$this->fieldName][]['target_id'] = $this->term1->id();
$node[$this->fieldName][]['target_id'] = $this->term2->id();
@@ -129,8 +130,8 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
$this->drupalLogin($this->editorUser);
$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);
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$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
@@ -139,16 +140,16 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
$this->assertTrue($form_tokens_found, 'Form tokens found in output.');
if ($form_tokens_found) {
$post = array(
$post = [
'form_id' => 'quickedit_field_form',
'form_token' => $token_match[1],
'form_build_id' => $build_id_match[1],
$this->fieldName . '[target_id]' => implode(', ', array($this->term1->getName(), 'new term', $this->term2->getName())),
$this->fieldName . '[target_id]' => implode(', ', [$this->term1->getName(), 'new term', $this->term2->getName()]),
'op' => t('Save'),
);
];
// 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']);
@@ -160,8 +161,8 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
// Load the form again, which should now get it back from
// 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);
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$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
@@ -169,15 +170,15 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
// taxonomy terms, including the one that has just been newly created and
// which is not yet stored.
$this->setRawContent($ajax_commands[0]['data']);
$expected = array(
$expected = [
$this->term1->getName() . ' (' . $this->term1->id() . ')',
'new term',
$this->term2->getName() . ' (' . $this->term2->id() . ')',
);
];
$this->assertFieldByName($this->fieldName . '[target_id]', implode(', ', $expected));
// Save the entity.
$post = array('nocssjs' => 'true');
$post = ['nocssjs' => 'true'];
$response = $this->drupalPostWithFormat('quickedit/entity/node/' . $this->node->id(), 'json', $post);
$this->assertResponse(200);
@@ -27,13 +27,13 @@ class QuickEditLoadingTest extends WebTestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'contextual',
'quickedit',
'filter',
'node',
'image',
);
];
/**
* An user with permissions to create and edit articles.
@@ -53,37 +53,43 @@ class QuickEditLoadingTest extends WebTestBase {
parent::setUp();
// Create a text format.
$filtered_html_format = FilterFormat::create(array(
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(),
));
'filters' => [],
]);
$filtered_html_format->save();
// Create a node type.
$this->drupalCreateContentType(array(
$this->drupalCreateContentType([
'type' => 'article',
'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(
$this->drupalCreateNode([
'type' => 'article',
'body' => array(
0 => array(
'body' => [
0 => [
'value' => '<p>How are you?</p>',
'format' => 'filtered_html',
)
),
]
],
'revision_log' => $this->randomString(),
));
]);
// Create 2 users, the only difference being the ability to use in-place
// editing
$basic_permissions = array('access content', 'create article content', 'edit any article content', 'use text format filtered_html', 'access contextual links');
$basic_permissions = ['access content', 'create article content', 'edit any article content', 'use text format filtered_html', 'access contextual links'];
$this->authorUser = $this->drupalCreateUser($basic_permissions);
$this->editorUser = $this->drupalCreateUser(array_merge($basic_permissions, array('access in-place editing')));
$this->editorUser = $this->drupalCreateUser(array_merge($basic_permissions, ['access in-place editing']));
}
/**
@@ -97,29 +103,31 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertNoRaw('core/modules/quickedit/js/quickedit.js', 'Quick Edit library not loaded.');
$this->assertNoRaw('core/modules/quickedit/js/editors/formEditor.js', "'form' in-place editor not loaded.");
// HTML annotation does not exist for users without permission to in-place
// edit.
// HTML annotation and title class does not exist for users without
// permission to in-place edit.
$this->assertNoRaw('data-quickedit-entity-id="node/1"');
$this->assertNoRaw('data-quickedit-field-id="node/1/body/en/full"');
$this->assertNoFieldByXPath('//h1[contains(@class, "js-quickedit-page-title")]');
// Retrieving the metadata should result in an empty 403 response.
$post = array('fields[0]' => 'node/1/body/en/full');
$post = ['fields[0]' => 'node/1/body/en/full'];
$response = $this->drupalPostWithFormat(Url::fromRoute('quickedit.metadata'), 'json', $post);
$this->assertIdentical('{"message":""}', $response);
$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
// 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 = array('editors[0]' => 'form') + $this->getAjaxPageStatePostData();
$post = ['editors[0]' => 'form'] + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/attachments', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertIdentical('{}', $response);
$message = Json::encode(['message' => "A fatal error occurred: The 'access in-place editing' permission is required."]);
$this->assertIdentical($message, $response);
$this->assertResponse(403);
$post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData();
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertIdentical('{}', $response);
$this->assertIdentical($message, $response);
$this->assertResponse(403);
$edit = array();
$edit = [];
$edit['form_id'] = 'quickedit_field_form';
$edit['form_token'] = 'xIOzMjuc-PULKsRn_KxFn7xzNk5Bx7XKXLfQfw1qOnA';
$edit['form_build_id'] = 'form-kVmovBpyX-SJfTT5kY0pjTV35TV-znor--a64dEnMR8';
@@ -128,11 +136,11 @@ class QuickEditLoadingTest extends WebTestBase {
$edit['body[0][format]'] = 'filtered_html';
$edit['op'] = t('Save');
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', '', $edit, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertIdentical('{}', $response);
$this->assertIdentical($message, $response);
$this->assertResponse(403);
$post = array('nocssjs' => 'true');
$post = ['nocssjs' => 'true'];
$response = $this->drupalPostWithFormat('quickedit/entity/' . 'node/1', 'json', $post);
$this->assertIdentical('{"message":""}', $response);
$this->assertIdentical(Json::encode(['message' => "The 'access in-place editing' permission is required."]), $response);
$this->assertResponse(403);
}
@@ -151,9 +159,11 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertTrue(in_array('quickedit/quickedit', $libraries), 'Quick Edit library loaded.');
$this->assertFalse(in_array('quickedit/quickedit.inPlaceEditor.form', $libraries), "'form' in-place editor not loaded.");
// HTML annotation must always exist (to not break the render cache).
// HTML annotation and title class must always exist (to not break the
// render cache).
$this->assertRaw('data-quickedit-entity-id="node/1"');
$this->assertRaw('data-quickedit-field-id="node/1/body/en/full"');
$this->assertFieldByXPath('//h1[contains(@class, "js-quickedit-page-title")]');
// There should be only one revision so far.
$node = Node::load(1);
@@ -163,16 +173,16 @@ class QuickEditLoadingTest extends WebTestBase {
// Retrieving the metadata should result in a 200 JSON response.
$htmlPageDrupalSettings = $this->drupalSettings;
$post = array('fields[0]' => 'node/1/body/en/full');
$post = ['fields[0]' => 'node/1/body/en/full'];
$response = $this->drupalPostWithFormat('quickedit/metadata', 'json', $post);
$this->assertResponse(200);
$expected = array(
'node/1/body/en/full' => array(
$expected = [
'node/1/body/en/full' => [
'label' => 'Body',
'access' => TRUE,
'editor' => 'form',
)
);
]
];
$this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.');
// Restore drupalSettings to build the next requests; simpletest wipes them
// after a JSON response.
@@ -181,8 +191,8 @@ class QuickEditLoadingTest extends WebTestBase {
// Retrieving the attachments should result in a 200 response, containing:
// 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);
$post = ['editors[0]' => 'form'] + $this->getAjaxPageStatePostData();
$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.
@@ -193,8 +203,8 @@ 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);
$post = ['nocssjs' => 'true', 'reset' => 'true'] + $this->getAjaxPageStatePostData();
$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.');
@@ -207,35 +217,35 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertTrue($form_tokens_found, 'Form tokens found in output.');
if ($form_tokens_found) {
$edit = array(
$edit = [
'body[0][summary]' => '',
'body[0][value]' => '<p>Fine thanks.</p>',
'body[0][format]' => 'filtered_html',
'op' => t('Save'),
);
$post = array(
];
$post = [
'form_id' => 'quickedit_field_form',
'form_token' => $token_match[1],
'form_build_id' => $build_id_match[1],
);
];
$post += $edit + $this->getAjaxPageStatePostData();
// 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.');
$this->assertIdentical('quickeditFieldFormSaved', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldFormSaved command.');
$this->assertTrue(strpos($ajax_commands[0]['data'], 'Fine thanks.'), 'Form value saved and printed back.');
$this->assertIdentical($ajax_commands[0]['other_view_modes'], array(), 'Field was not rendered in any other view mode.');
$this->assertIdentical($ajax_commands[0]['other_view_modes'], [], 'Field was not rendered in any other view mode.');
// Ensure the text on the original node did not change yet.
$this->drupalGet('node/1');
$this->assertText('How are you?');
// Save the entity by moving the PrivateTempStore values to entity storage.
$post = array('nocssjs' => 'true');
$post = ['nocssjs' => 'true'];
$response = $this->drupalPostWithFormat('quickedit/entity/' . 'node/1', 'json', $post);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
@@ -263,8 +273,8 @@ class QuickEditLoadingTest extends WebTestBase {
$node_type->save();
// Retrieve field form.
$post = array('nocssjs' => 'true', 'reset' => 'true');
$response = $this->drupalPost('quickedit/form/' . 'node/1/body/en/full', 'application/vnd.drupal-ajax', $post);
$post = ['nocssjs' => 'true', 'reset' => 'true'];
$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.');
@@ -275,13 +285,13 @@ class QuickEditLoadingTest extends WebTestBase {
preg_match('/\sname="form_token" value="([^"]+)"/', $ajax_commands[0]['data'], $token_match);
preg_match('/\sname="form_build_id" value="([^"]+)"/', $ajax_commands[0]['data'], $build_id_match);
$edit['body[0][value]'] = '<p>kthxbye</p>';
$post = array(
$post = [
'form_id' => 'quickedit_field_form',
'form_token' => $token_match[1],
'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.');
@@ -289,7 +299,7 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertTrue(strpos($ajax_commands[0]['data'], 'kthxbye'), 'Form value saved and printed back.');
// Save the entity.
$post = array('nocssjs' => 'true');
$post = ['nocssjs' => 'true'];
$response = $this->drupalPostWithFormat('quickedit/entity/' . 'node/1', 'json', $post);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
@@ -316,21 +326,21 @@ class QuickEditLoadingTest extends WebTestBase {
// Ensure that the full page title is actually in-place editable
$node = Node::load(1);
$elements = $this->xpath('//h1/span[@data-quickedit-field-id="node/1/title/en/full" and normalize-space(text())=:title]', array(':title' => $node->label()));
$elements = $this->xpath('//h1/span[@data-quickedit-field-id="node/1/title/en/full" and normalize-space(text())=:title]', [':title' => $node->label()]);
$this->assertTrue(!empty($elements), 'Title with data-quickedit-field-id attribute found.');
// Retrieving the metadata should result in a 200 JSON response.
$htmlPageDrupalSettings = $this->drupalSettings;
$post = array('fields[0]' => 'node/1/title/en/full');
$post = ['fields[0]' => 'node/1/title/en/full'];
$response = $this->drupalPostWithFormat('quickedit/metadata', 'json', $post);
$this->assertResponse(200);
$expected = array(
'node/1/title/en/full' => array(
$expected = [
'node/1/title/en/full' => [
'label' => 'Title',
'access' => TRUE,
'editor' => 'plain_text',
)
);
]
];
$this->assertIdentical(Json::decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.');
// Restore drupalSettings to build the next requests; simpletest wipes them
// after a JSON response.
@@ -338,8 +348,8 @@ 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);
$post = ['nocssjs' => 'true', 'reset' => 'true'] + $this->getAjaxPageStatePostData();
$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.');
@@ -353,20 +363,20 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertTrue($form_tokens_found, 'Form tokens found in output.');
if ($form_tokens_found) {
$edit = array(
$edit = [
'title[0][value]' => 'Obligatory question',
'op' => t('Save'),
);
$post = array(
];
$post = [
'form_id' => 'quickedit_field_form',
'form_token' => $token_match[1],
'form_build_id' => $build_id_match[1],
);
];
$post += $edit + $this->getAjaxPageStatePostData();
// 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.');
@@ -378,7 +388,7 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertNoText('Obligatory question');
// Save the entity by moving the PrivateTempStore values to entity storage.
$post = array('nocssjs' => 'true');
$post = ['nocssjs' => 'true'];
$response = $this->drupalPostWithFormat('quickedit/entity/' . 'node/1', 'json', $post);
$this->assertResponse(200);
$ajax_commands = Json::decode($response);
@@ -399,9 +409,9 @@ class QuickEditLoadingTest extends WebTestBase {
*/
public function testDisplayOptions() {
$node = Node::load('1');
$display_settings = array(
$display_settings = [
'label' => 'inline',
);
];
$build = $node->body->view($display_settings);
$output = \Drupal::service('renderer')->renderRoot($build);
$this->assertFalse(strpos($output, 'data-quickedit-field-id'), 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
@@ -411,14 +421,14 @@ class QuickEditLoadingTest extends WebTestBase {
* Tests that Quick Edit works with custom render pipelines.
*/
public function testCustomPipeline() {
\Drupal::service('module_installer')->install(array('quickedit_test'));
\Drupal::service('module_installer')->install(['quickedit_test']);
$custom_render_url = 'quickedit/form/node/1/body/en/quickedit_test-custom-render-data';
$this->drupalLogin($this->editorUser);
// 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);
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$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
@@ -427,7 +437,7 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertTrue($form_tokens_found, 'Form tokens found in output.');
if ($form_tokens_found) {
$post = array(
$post = [
'form_id' => 'quickedit_field_form',
'form_token' => $token_match[1],
'form_build_id' => $build_id_match[1],
@@ -435,21 +445,21 @@ class QuickEditLoadingTest extends WebTestBase {
'body[0][value]' => '<p>Fine thanks.</p>',
'body[0][format]' => 'filtered_html',
'op' => t('Save'),
);
];
// Assume there is another field on this page, which doesn't use a custom
// render pipeline, but the default one, and it uses the "full" view mode.
$post += array('other_view_modes[]' => 'full');
$post += ['other_view_modes[]' => 'full'];
// 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.');
$this->assertIdentical('quickeditFieldFormSaved', $ajax_commands[0]['command'], 'The first AJAX command is a quickeditFieldFormSaved command.');
$this->assertTrue(strpos($ajax_commands[0]['data'], 'Fine thanks.'), 'Form value saved and printed back.');
$this->assertTrue(strpos($ajax_commands[0]['data'], '<div class="quickedit-test-wrapper">') !== FALSE, 'Custom render pipeline used to render the value.');
$this->assertIdentical(array_keys($ajax_commands[0]['other_view_modes']), array('full'), 'Field was also rendered in the "full" view mode.');
$this->assertIdentical(array_keys($ajax_commands[0]['other_view_modes']), ['full'], 'Field was also rendered in the "full" view mode.');
$this->assertTrue(strpos($ajax_commands[0]['other_view_modes']['full'], 'Fine thanks.'), '"full" version of field contains the form value.');
}
}
@@ -461,8 +471,8 @@ class QuickEditLoadingTest extends WebTestBase {
public function testConcurrentEdit() {
$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);
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$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);
@@ -472,7 +482,7 @@ class QuickEditLoadingTest extends WebTestBase {
$this->assertTrue($form_tokens_found, 'Form tokens found in output.');
if ($form_tokens_found) {
$post = array(
$post = [
'nocssjs' => 'true',
'form_id' => 'quickedit_field_form',
'form_token' => $token_match[1],
@@ -481,16 +491,16 @@ class QuickEditLoadingTest extends WebTestBase {
'body[0][value]' => '<p>Fine thanks.</p>',
'body[0][format]' => 'filtered_html',
'op' => t('Save'),
);
];
// Save the node on the regular node edit form.
$this->drupalPostForm('node/1/edit', array(), t('Save'));
$this->drupalPostForm('node/1/edit', [], t('Save'));
// Ensure different save timestamps for field editing.
sleep(2);
// 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.');
@@ -503,7 +513,7 @@ class QuickEditLoadingTest extends WebTestBase {
* Tests that Quick Edit's data- attributes are present for content blocks.
*/
public function testContentBlock() {
\Drupal::service('module_installer')->install(array('block_content'));
\Drupal::service('module_installer')->install(['block_content']);
// Create and place a content_block block.
$block = BlockContent::create([
@@ -554,7 +564,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.');