.../Core/Entity/Entity/EntityFormDisplay.php | 6 +++--- .../user/src/Tests/UserRegistrationTest.php | 24 +++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index abb00d9..c864ceb 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -8,11 +8,11 @@ namespace Drupal\Core\Entity\Entity; use Drupal\Core\Cache\Cache; +use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityDisplayPluginCollection; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\EntityDisplayBase; -use Drupal\Core\Field\FieldConfigInterface; use Drupal\Core\Form\FormStateInterface; /** @@ -171,11 +171,11 @@ public function buildForm(FieldableEntityInterface $entity, array &$form, FormSt // Associate the cache tags for the field definition & field storage // definition. $field_definition = $this->getFieldDefinition($name); - if ($field_definition instanceof FieldConfigInterface) { + if ($field_definition instanceof ConfigEntityInterface) { // @todo: Use RendererInterface::addDependency() once https://www.drupal.org/node/2444231 lands. $form['name']['#cache']['tags'] = $field_definition->getCacheTags(); $field_storage_definition = $field_definition->getFieldStorageDefinition(); - if ($field_storage_definition instanceof FieldConfigInterface) { + if ($field_storage_definition instanceof ConfigEntityInterface) { $form['name']['#cache']['tags'] = Cache::mergeTags($form['name']['#cache']['tags'], $field_storage_definition->getCacheTags()); } } diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php index 24e6972..ff3fa30 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/src/Tests/UserRegistrationTest.php @@ -227,16 +227,10 @@ function testRegistrationWithUserFields() { entity_get_form_display('user', 'user', 'register') ->setComponent('test_user_field', array('type' => 'test_field_widget')) ->save(); - $check_cache_tags = function() { - $this->assertCacheTag('config:core.entity_form_display.user.user.register'); - $this->assertCacheTag('config:field.field.user.user.test_user_field'); - $this->assertCacheTag('config:field.storage.user.test_user_field'); - $this->assertCacheTag('config:user.settings'); - }; $this->drupalGet('user/register'); $this->assertText($field->label(), 'The field appears on user registration form'); - $check_cache_tags(); + $this->assertRegistrationFormCacheTagsWithUserFields(); // Check that validation errors are correctly reported. $edit = array(); @@ -245,12 +239,12 @@ function testRegistrationWithUserFields() { // Missing input in required field. $edit['test_user_field[0][value]'] = ''; $this->drupalPostForm(NULL, $edit, t('Create new account')); - $check_cache_tags(); + $this->assertRegistrationFormCacheTagsWithUserFields(); $this->assertRaw(t('@name field is required.', array('@name' => $field->label())), 'Field validation error was correctly reported.'); // Invalid input. $edit['test_user_field[0][value]'] = '-1'; $this->drupalPostForm(NULL, $edit, t('Create new account')); - $check_cache_tags(); + $this->assertRegistrationFormCacheTagsWithUserFields(); $this->assertRaw(t('%name does not accept the value -1.', array('%name' => $field->label())), 'Field validation error was correctly reported.'); // Submit with valid data. @@ -267,7 +261,7 @@ function testRegistrationWithUserFields() { $field_storage->save(); foreach (array('js', 'nojs') as $js) { $this->drupalGet('user/register'); - $check_cache_tags(); + $this->assertRegistrationFormCacheTagsWithUserFields(); // Add two inputs. $value = rand(1, 255); $edit = array(); @@ -295,4 +289,14 @@ function testRegistrationWithUserFields() { } } + /** + * Asserts the presence of cache tags on registration form with user fields. + */ + protected function assertRegistrationFormCacheTagsWithUserFields() { + $this->assertCacheTag('config:core.entity_form_display.user.user.register'); + $this->assertCacheTag('config:field.field.user.user.test_user_field'); + $this->assertCacheTag('config:field.storage.user.test_user_field'); + $this->assertCacheTag('config:user.settings'); + } + }