Commit cf553a00 authored by catch's avatar catch

Issue #2715589 by claudiu.cristea, jibran, amateescu: Remove stale...

Issue #2715589 by claudiu.cristea, jibran, amateescu: Remove stale 'handler_submit' setting from the ER field configs
parent b0a7be53
......@@ -6,10 +6,10 @@
*/
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
/**
* Re-save all field storage config objects to add 'custom_storage' property.
*/
......@@ -59,3 +59,26 @@ function field_post_update_email_widget_size_setting() {
return t('The new size setting for email widgets has been added.');
}
/**
* Remove the stale 'handler_submit' setting for entity_reference fields.
*/
function field_post_update_remove_handler_submit_setting() {
$config = \Drupal::configFactory();
/** @var \Drupal\Core\Field\FieldTypePluginManager $field_type_manager */
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
// Iterate on all field configs.
foreach ($config->listAll('field.field.') as $field_id) {
$field = $config->getEditable($field_id);
$class = $field_type_manager->getPluginClass($field->get('field_type'));
// Deal only with entity reference fields and descendants.
if ($class === EntityReferenceItem::class || is_subclass_of($class, EntityReferenceItem::class)) {
if ($field->get('settings.handler_submit')) {
// Remove 'handler_settings' from settings.
$field->clear('settings.handler_submit')->save();
}
}
}
}
<?php
/**
* @file
* Provides necessary database additions for testing
* field_post_update_remove_handler_submit_setting()
*/
use Drupal\Core\Database\Database;
$connection = Database::getConnection();
$config = unserialize($connection->select('config', 'c')
->fields('c', ['data'])
->condition('collection', '')
->condition('name', 'field.field.node.article.field_tags')
->execute()
->fetchField());
$config['settings']['handler_submit'] = 'Change handler';
$connection->update('config')
->fields(['data' => serialize($config)])
->condition('collection', '')
->condition('name', 'field.field.node.article.field_tags')
->execute();
......@@ -36,6 +36,7 @@ protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.views_entity_reference_plugins-2429191.php',
__DIR__ . '/../../../fixtures/update/drupal-8.remove_handler_submit_setting-2715589.php',
];
}
......@@ -141,4 +142,21 @@ protected function assertEntityRefDependency(Config $config, $present) {
$this->assertEqual(in_array('entity_reference', $dependencies['module']), $present);
}
/**
* Tests field_post_update_remove_handler_submit_setting().
*
* @see field_post_update_remove_handler_submit_setting()
*/
public function testEntityReferenceFieldConfigCleanUpdate() {
$field_config = $this->config('field.field.node.article.field_tags');
// Check that 'handler_submit' key exists in field config settings.
$this->assertEquals('Change handler', $field_config->get('settings.handler_submit'));
$this->runUpdates();
$field_config = $this->config('field.field.node.article.field_tags');
// Check that 'handler_submit' has been removed from field config settings.
$this->assertArrayNotHasKey('handler_submit', $field_config->get('settings'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment