Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -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,
);
];
}
}

View file

@ -65,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]);
}
@ -86,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.

View file

@ -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;

View file

@ -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;

View file

@ -25,11 +25,11 @@ class FormEditor extends InPlaceEditorBase {
* {@inheritdoc}
*/
public function getAttachments() {
return array(
'library' => array(
return [
'library' => [
'quickedit/quickedit.inPlaceEditor.form',
),
);
],
];
}
}

View file

@ -28,11 +28,11 @@ class PlainTextEditor extends InPlaceEditorBase {
* {@inheritdoc}
*/
public function getAttachments() {
return array(
'library' => array(
return [
'library' => [
'quickedit/quickedit.inPlaceEditor.plainText',
),
);
],
];
}
}

View file

@ -18,8 +18,8 @@ abstract class InPlaceEditorBase extends PluginBase implements InPlaceEditorInte
/**
* {@inheritdoc}
*/
function getMetadata(FieldItemListInterface $items) {
return array();
public function getMetadata(FieldItemListInterface $items) {
return [];
}
}

View file

@ -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();

View file

@ -25,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.
@ -72,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',
@ -83,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')
@ -114,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();
@ -130,7 +130,7 @@ 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();
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response);
@ -140,13 +140,13 @@ 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, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
@ -161,7 +161,7 @@ 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();
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($quickedit_uri, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response);
@ -170,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);

View file

@ -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,19 +53,19 @@ 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.
@ -74,22 +74,22 @@ class QuickEditLoadingTest extends WebTestBase {
$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']));
}
/**
@ -103,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';
@ -134,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);
}
@ -157,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);
@ -169,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.
@ -187,7 +191,7 @@ 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();
$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.');
@ -199,7 +203,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();
$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);
@ -213,17 +217,17 @@ 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
@ -234,14 +238,14 @@ class QuickEditLoadingTest extends WebTestBase {
$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);
@ -269,7 +273,7 @@ class QuickEditLoadingTest extends WebTestBase {
$node_type->save();
// Retrieve field form.
$post = array('nocssjs' => 'true', 'reset' => 'true');
$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);
@ -281,11 +285,11 @@ 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', '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$this->assertResponse(200);
@ -295,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);
@ -322,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.
@ -344,7 +348,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();
$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);
@ -359,15 +363,15 @@ 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
@ -384,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);
@ -405,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.');
@ -417,13 +421,13 @@ 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();
$post = ['nocssjs' => 'true'] + $this->getAjaxPageStatePostData();
$response = $this->drupalPost($custom_render_url, '', $post, ['query' => [MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax']]);
$ajax_commands = Json::decode($response);
@ -433,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],
@ -441,10 +445,10 @@ 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.
@ -455,7 +459,7 @@ class QuickEditLoadingTest extends WebTestBase {
$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.');
}
}
@ -467,7 +471,7 @@ class QuickEditLoadingTest extends WebTestBase {
public function testConcurrentEdit() {
$this->drupalLogin($this->editorUser);
$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->assertResponse(200);
$ajax_commands = Json::decode($response);
@ -478,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],
@ -487,10 +491,10 @@ 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);
@ -509,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([