Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -51,7 +51,7 @@
|
|||
|
||||
// Reposition the entity toolbar as the viewport and the position within
|
||||
// the viewport changes.
|
||||
$(window).on('resize.quickedit scroll.quickedit', debounce($.proxy(this.windowChangeHandler, this), 150));
|
||||
$(window).on('resize.quickedit scroll.quickedit drupalViewportOffsetChange.quickedit', debounce($.proxy(this.windowChangeHandler, this), 150));
|
||||
|
||||
// Adjust the fence placement within which the entity toolbar may be
|
||||
// positioned.
|
||||
|
@ -141,7 +141,7 @@
|
|||
this.$fence.remove();
|
||||
|
||||
// Stop listening to additional events.
|
||||
$(window).off('resize.quickedit scroll.quickedit');
|
||||
$(window).off('resize.quickedit scroll.quickedit drupalViewportOffsetChange.quickedit');
|
||||
$(document).off('drupalViewportOffsetChange.quickedit');
|
||||
|
||||
Backbone.View.prototype.remove.call(this);
|
||||
|
|
|
@ -70,11 +70,11 @@ function hook_quickedit_editor_alter(&$editors) {
|
|||
* @see \Drupal\Core\Field\FieldItemListInterface::view()
|
||||
*/
|
||||
function hook_quickedit_render_field(Drupal\Core\Entity\EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
|
||||
return array(
|
||||
return [
|
||||
'#prefix' => '<div class="example-markup">',
|
||||
'field' => $entity->getTranslation($langcode)->get($field_name)->view($view_mode_id),
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,12 +22,12 @@ function quickedit_help($route_name, RouteMatchInterface $route_match) {
|
|||
switch ($route_name) {
|
||||
case 'help.page.quickedit':
|
||||
$output = '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Quick Edit module allows users with the <a href=":quickedit_permission">Access in-place editing</a> and <a href=":contextual_permission">Use contextual links</a> permissions to edit field content without visiting a separate page. For more information, see the <a href=":handbook_url">online documentation for the Quick Edit module</a>.', array(':handbook_url' => 'https://www.drupal.org/documentation/modules/edit', ':quickedit_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-quickedit')), ':contextual_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-contextual')))) . '</p>';
|
||||
$output .= '<p>' . t('The Quick Edit module allows users with the <a href=":quickedit_permission">Access in-place editing</a> and <a href=":contextual_permission">Use contextual links</a> permissions to edit field content without visiting a separate page. For more information, see the <a href=":handbook_url">online documentation for the Quick Edit module</a>.', [':handbook_url' => 'https://www.drupal.org/documentation/modules/edit', ':quickedit_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-quickedit']), ':contextual_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-contextual'])]) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Editing content in-place') . '</dt>';
|
||||
$output .= '<dd>';
|
||||
$output .= '<p>' . t('To edit content in place, you need to activate quick edit mode for a content item. Activate quick edit mode by choosing Quick edit from the contextual links for an area displaying the content (see the <a href=":contextual">Contextual Links module help</a> for more information about how to use contextual links).', array(':contextual' => \Drupal::url('help.page', array('name' => 'contextual')))) . '</p>';
|
||||
$output .= '<p>' . t('To edit content in place, you need to activate quick edit mode for a content item. Activate quick edit mode by choosing Quick edit from the contextual links for an area displaying the content (see the <a href=":contextual">Contextual Links module help</a> for more information about how to use contextual links).', [':contextual' => \Drupal::url('help.page', ['name' => 'contextual'])]) . '</p>';
|
||||
$output .= '<p>' . t('Once quick edit mode is activated, you will be able to edit the individual fields of your content. In the default theme, with a JavaScript-enabled browser and a mouse, the output of different fields in your content is outlined in blue, a pop-up gives the field name as you hover over the field output, and clicking on a field activates the editor. Closing the pop-up window ends quick edit mode.') . '</p>';
|
||||
$output .= '</dd>';
|
||||
$output .= '</dl>';
|
||||
|
@ -108,7 +108,7 @@ function quickedit_field_formatter_info_alter(&$info) {
|
|||
foreach ($info as $key => $settings) {
|
||||
// Set in-place editor to 'form' if none is supplied.
|
||||
if (empty($settings['quickedit'])) {
|
||||
$info[$key]['quickedit'] = array('editor' => 'form');
|
||||
$info[$key]['quickedit'] = ['editor' => 'form'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,10 @@ function quickedit_field_formatter_info_alter(&$info) {
|
|||
* Implements hook_preprocess_HOOK() for the page title template.
|
||||
*/
|
||||
function quickedit_preprocess_page_title(&$variables) {
|
||||
$variables['title_attributes']['class'][] = 'js-quickedit-page-title';
|
||||
$variables['#cache']['contexts'][] = 'user.permissions';
|
||||
if (\Drupal::currentUser()->hasPermission('access in-place editing')) {
|
||||
$variables['title_attributes']['class'][] = 'js-quickedit-page-title';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ class PlainTextEditor extends InPlaceEditorBase {
|
|||
* {@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();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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([
|
||||
|
|
|
@ -12,11 +12,11 @@ use Drupal\Core\Entity\EntityInterface;
|
|||
*/
|
||||
function quickedit_test_quickedit_render_field(EntityInterface $entity, $field_name, $view_mode_id, $langcode) {
|
||||
$entity = \Drupal::entityManager()->getTranslationFromContext($entity, $langcode);
|
||||
return array(
|
||||
return [
|
||||
'#prefix' => '<div class="quickedit-test-wrapper">',
|
||||
'field' => $entity->get($field_name)->view($view_mode_id),
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,11 +42,11 @@ class WysiwygEditor extends InPlaceEditorBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttachments() {
|
||||
return array(
|
||||
'library' => array(
|
||||
return [
|
||||
'library' => [
|
||||
'quickedit_test/not-existing-wysiwyg',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,13 +53,13 @@ class EditorSelectionTest extends QuickEditTestBase {
|
|||
$this->createFieldWithStorage(
|
||||
$field_name, 'string', 1, 'Simple text field',
|
||||
// Instance settings.
|
||||
array(),
|
||||
[],
|
||||
// Widget type & settings.
|
||||
'string_textfield',
|
||||
array('size' => 42),
|
||||
['size' => 42],
|
||||
// 'default' formatter type & settings.
|
||||
'string',
|
||||
array()
|
||||
[]
|
||||
);
|
||||
|
||||
// Create an entity with values for this text field.
|
||||
|
@ -84,7 +84,7 @@ class EditorSelectionTest extends QuickEditTestBase {
|
|||
*/
|
||||
public function testTextWysiwyg() {
|
||||
// Enable edit_test module so that the 'wysiwyg' editor becomes available.
|
||||
$this->enableModules(array('quickedit_test'));
|
||||
$this->enableModules(['quickedit_test']);
|
||||
$this->editorManager = $this->container->get('plugin.manager.quickedit.editor');
|
||||
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
|
||||
|
||||
|
@ -92,13 +92,13 @@ class EditorSelectionTest extends QuickEditTestBase {
|
|||
$this->createFieldWithStorage(
|
||||
$field_name, 'text', 1, 'Long text field',
|
||||
// Instance settings.
|
||||
array(),
|
||||
[],
|
||||
// Widget type & settings.
|
||||
'text_textarea',
|
||||
array('size' => 42),
|
||||
['size' => 42],
|
||||
// 'default' formatter type & settings.
|
||||
'text_default',
|
||||
array()
|
||||
[]
|
||||
);
|
||||
|
||||
// Create an entity with values for this text field.
|
||||
|
@ -129,13 +129,13 @@ class EditorSelectionTest extends QuickEditTestBase {
|
|||
$this->createFieldWithStorage(
|
||||
$field_name, 'integer', 1, 'Simple number field',
|
||||
// Instance settings.
|
||||
array(),
|
||||
[],
|
||||
// Widget type & settings.
|
||||
'number',
|
||||
array(),
|
||||
[],
|
||||
// 'default' formatter type & settings.
|
||||
'number_integer',
|
||||
array()
|
||||
[]
|
||||
);
|
||||
|
||||
// Create an entity with values for this text field.
|
||||
|
|
|
@ -18,7 +18,7 @@ class MetadataGeneratorTest extends QuickEditTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('quickedit_test');
|
||||
public static $modules = ['quickedit_test'];
|
||||
|
||||
/**
|
||||
* The manager for editor plugins.
|
||||
|
@ -66,26 +66,26 @@ class MetadataGeneratorTest extends QuickEditTestBase {
|
|||
$this->createFieldWithStorage(
|
||||
$field_1_name, 'string', 1, $field_1_label,
|
||||
// Instance settings.
|
||||
array(),
|
||||
[],
|
||||
// Widget type & settings.
|
||||
'string_textfield',
|
||||
array('size' => 42),
|
||||
['size' => 42],
|
||||
// 'default' formatter type & settings.
|
||||
'string',
|
||||
array()
|
||||
[]
|
||||
);
|
||||
$field_2_name = 'field_nr';
|
||||
$field_2_label = 'Simple number field';
|
||||
$this->createFieldWithStorage(
|
||||
$field_2_name, 'integer', 1, $field_2_label,
|
||||
// Instance settings.
|
||||
array(),
|
||||
[],
|
||||
// Widget type & settings.
|
||||
'number',
|
||||
array(),
|
||||
[],
|
||||
// 'default' formatter type & settings.
|
||||
'number_integer',
|
||||
array()
|
||||
[]
|
||||
);
|
||||
|
||||
// Create an entity with values for this text field.
|
||||
|
@ -98,21 +98,21 @@ class MetadataGeneratorTest extends QuickEditTestBase {
|
|||
// Verify metadata for field 1.
|
||||
$items_1 = $entity->get($field_1_name);
|
||||
$metadata_1 = $this->metadataGenerator->generateFieldMetadata($items_1, 'default');
|
||||
$expected_1 = array(
|
||||
$expected_1 = [
|
||||
'access' => TRUE,
|
||||
'label' => 'Plain text field',
|
||||
'editor' => 'plain_text',
|
||||
);
|
||||
];
|
||||
$this->assertEqual($expected_1, $metadata_1, 'The correct metadata is generated for the first field.');
|
||||
|
||||
// Verify metadata for field 2.
|
||||
$items_2 = $entity->get($field_2_name);
|
||||
$metadata_2 = $this->metadataGenerator->generateFieldMetadata($items_2, 'default');
|
||||
$expected_2 = array(
|
||||
$expected_2 = [
|
||||
'access' => TRUE,
|
||||
'label' => 'Simple number field',
|
||||
'editor' => 'form',
|
||||
);
|
||||
];
|
||||
$this->assertEqual($expected_2, $metadata_2, 'The correct metadata is generated for the second field.');
|
||||
}
|
||||
|
||||
|
@ -134,24 +134,24 @@ class MetadataGeneratorTest extends QuickEditTestBase {
|
|||
$this->createFieldWithStorage(
|
||||
$field_name, 'text', 1, $field_label,
|
||||
// Instance settings.
|
||||
array(),
|
||||
[],
|
||||
// Widget type & settings.
|
||||
'text_textfield',
|
||||
array('size' => 42),
|
||||
['size' => 42],
|
||||
// 'default' formatter type & settings.
|
||||
'text_default',
|
||||
array()
|
||||
[]
|
||||
);
|
||||
|
||||
// Create a text format.
|
||||
$full_html_format = FilterFormat::create(array(
|
||||
$full_html_format = FilterFormat::create([
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
'weight' => 1,
|
||||
'filters' => array(
|
||||
'filter_htmlcorrector' => array('status' => 1),
|
||||
),
|
||||
));
|
||||
'filters' => [
|
||||
'filter_htmlcorrector' => ['status' => 1],
|
||||
],
|
||||
]);
|
||||
$full_html_format->save();
|
||||
|
||||
// Create an entity with values for this rich text field.
|
||||
|
@ -164,14 +164,14 @@ class MetadataGeneratorTest extends QuickEditTestBase {
|
|||
// Verify metadata.
|
||||
$items = $entity->get($field_name);
|
||||
$metadata = $this->metadataGenerator->generateFieldMetadata($items, 'default');
|
||||
$expected = array(
|
||||
$expected = [
|
||||
'access' => TRUE,
|
||||
'label' => 'Rich text field',
|
||||
'editor' => 'wysiwyg',
|
||||
'custom' => array(
|
||||
'custom' => [
|
||||
'format' => 'full_html'
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->assertEqual($expected, $metadata); //, 'The correct metadata (including custom metadata) is generated.');
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ abstract class QuickEditTestBase extends KernelTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fields = new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS);
|
||||
$this->fields = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
|
||||
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('entity_test');
|
||||
$this->installConfig(array('field', 'filter'));
|
||||
$this->installConfig(['field', 'filter']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,12 +67,12 @@ abstract class QuickEditTestBase extends KernelTestBase {
|
|||
*/
|
||||
protected function createFieldWithStorage($field_name, $type, $cardinality, $label, $field_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) {
|
||||
$field_storage = $field_name . '_field_storage';
|
||||
$this->fields->$field_storage = FieldStorageConfig::create(array(
|
||||
$this->fields->$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => $type,
|
||||
'cardinality' => $cardinality,
|
||||
));
|
||||
]);
|
||||
$this->fields->$field_storage->save();
|
||||
|
||||
$field = $field_name . '_field';
|
||||
|
@ -87,18 +87,18 @@ abstract class QuickEditTestBase extends KernelTestBase {
|
|||
$this->fields->$field->save();
|
||||
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, array(
|
||||
->setComponent($field_name, [
|
||||
'type' => $widget_type,
|
||||
'settings' => $widget_settings,
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
entity_get_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, array(
|
||||
->setComponent($field_name, [
|
||||
'label' => 'above',
|
||||
'type' => $formatter_type,
|
||||
'settings' => $formatter_settings
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,11 +43,11 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase {
|
|||
* @see \Drupal\Tests\edit\Unit\quickedit\Access\EditEntityFieldAccessCheckTest::testAccess()
|
||||
*/
|
||||
public function providerTestAccess() {
|
||||
$data = array();
|
||||
$data[] = array(TRUE, TRUE, AccessResult::allowed());
|
||||
$data[] = array(FALSE, TRUE, AccessResult::neutral());
|
||||
$data[] = array(TRUE, FALSE, AccessResult::neutral());
|
||||
$data[] = array(FALSE, FALSE, AccessResult::neutral());
|
||||
$data = [];
|
||||
$data[] = [TRUE, TRUE, AccessResult::allowed()];
|
||||
$data[] = [FALSE, TRUE, AccessResult::neutral()];
|
||||
$data[] = [TRUE, FALSE, AccessResult::neutral()];
|
||||
$data[] = [FALSE, FALSE, AccessResult::neutral()];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -108,15 +108,15 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase {
|
|||
* Provides test data for testAccessForbidden.
|
||||
*/
|
||||
public function providerTestAccessForbidden() {
|
||||
$data = array();
|
||||
$data = [];
|
||||
// Tests the access method without a field_name.
|
||||
$data[] = array(NULL, LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
$data[] = [NULL, LanguageInterface::LANGCODE_NOT_SPECIFIED];
|
||||
// Tests the access method with a non-existent field.
|
||||
$data[] = array('not_valid', LanguageInterface::LANGCODE_NOT_SPECIFIED);
|
||||
$data[] = ['not_valid', LanguageInterface::LANGCODE_NOT_SPECIFIED];
|
||||
// Tests the access method without a langcode.
|
||||
$data[] = array('valid', NULL);
|
||||
$data[] = ['valid', NULL];
|
||||
// Tests the access method with an invalid langcode.
|
||||
$data[] = array('valid', 'xx-lolspeak');
|
||||
$data[] = ['valid', 'xx-lolspeak'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -132,16 +132,16 @@ class EditEntityFieldAccessCheckTest extends UnitTestCase {
|
|||
|
||||
$entity->expects($this->any())
|
||||
->method('hasTranslation')
|
||||
->will($this->returnValueMap(array(
|
||||
array(LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE),
|
||||
array('xx-lolspeak', FALSE),
|
||||
)));
|
||||
->will($this->returnValueMap([
|
||||
[LanguageInterface::LANGCODE_NOT_SPECIFIED, TRUE],
|
||||
['xx-lolspeak', FALSE],
|
||||
]));
|
||||
$entity->expects($this->any())
|
||||
->method('hasField')
|
||||
->will($this->returnValueMap(array(
|
||||
array('valid', TRUE),
|
||||
array('not_valid', FALSE),
|
||||
)));
|
||||
->will($this->returnValueMap([
|
||||
['valid', TRUE],
|
||||
['not_valid', FALSE],
|
||||
]));
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
|
Reference in a new issue