From 0c80f49b90fce0c82a968f3878a779a5a7ce06fc Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 26 May 2015 10:38:46 +0100 Subject: [PATCH] Issue #2475483 by Arla, alexpott, Berdir, jeroen.b: Cannot quickedit an image or date field --- .../DependencyInjection/ClassResolver.php | 2 +- .../Core/TypedData/TypedDataManager.php | 2 + .../src/Tests/QuickEditLoadingTest.php | 51 ++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php index 997630ddf1af..be79a3ec81b9 100644 --- a/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php +++ b/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php @@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface; * Implements the class resolver interface supporting class names and services. */ class ClassResolver implements ClassResolverInterface, ContainerAwareInterface { - + use DependencySerializationTrait; use ContainerAwareTrait; /** diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index d9545db67b4a..89fa657ea9e8 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -11,6 +11,7 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; +use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\TypedData\Validation\ExecutionContextFactory; @@ -24,6 +25,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface; * Manages data type plugins. */ class TypedDataManager extends DefaultPluginManager { + use DependencySerializationTrait; /** * The validator used for validating typed data. diff --git a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php index af731697cfc0..6cb092409b1f 100644 --- a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php +++ b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php @@ -10,6 +10,9 @@ namespace Drupal\quickedit\Tests; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Unicode; use Drupal\block_content\Entity\BlockContent; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; +use Drupal\file\Entity\File; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\simpletest\WebTestBase; @@ -27,7 +30,13 @@ class QuickEditLoadingTest extends WebTestBase { * * @var array */ - public static $modules = array('contextual', 'quickedit', 'filter', 'node'); + public static $modules = array( + 'contextual', + 'quickedit', + 'filter', + 'node', + 'image', + ); /** * An user with permissions to create and edit articles. @@ -527,4 +536,44 @@ class QuickEditLoadingTest extends WebTestBase { $this->drupalGet(''); $this->assertRaw('data-quickedit-entity-id="block_content/1"'); } + + /** + * Tests that Quick Edit can handle an image field. + */ + public function testImageField() { + // Add an image field to the content type. + FieldStorageConfig::create([ + 'field_name' => 'field_image', + 'type' => 'image', + 'entity_type' => 'node', + ])->save(); + FieldConfig::create([ + 'field_name' => 'field_image', + 'field_type' => 'image', + 'label' => t('Image'), + 'entity_type' => 'node', + 'bundle' => 'article', + ])->save(); + entity_get_form_display('node', 'article', 'default') + ->setComponent('field_image', [ + 'type' => 'image_image', + ]) + ->save(); + + // Add an image to the node. + $this->drupalLogin($this->editorUser); + $image = $this->drupalGetTestFiles('image')[0]; + $this->drupalPostForm('node/1/edit', [ + 'files[field_image_0]' => $image->uri, + ], t('Upload')); + $this->drupalPostForm(NULL, [ + 'field_image[0][alt]' => 'Vivamus aliquet elit', + ], 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()); + $this->assertResponse(200); + $ajax_commands = Json::decode($response); + $this->assertIdentical('