diff --git a/core/lib/Drupal/Core/Field/FieldConfigStorageBase.php b/core/lib/Drupal/Core/Field/FieldConfigStorageBase.php index 29e61078966516b58a62f2e730aa85ed42559963..e99053de1947c3cacd7320682f394f70014b859a 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigStorageBase.php +++ b/core/lib/Drupal/Core/Field/FieldConfigStorageBase.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Field; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Config\Entity\ConfigEntityStorage; use Drupal\Core\Entity\EntityInterface; @@ -22,10 +23,12 @@ abstract class FieldConfigStorageBase extends ConfigEntityStorage { */ protected function mapFromStorageRecords(array $records) { foreach ($records as $id => &$record) { - $class = $this->fieldTypeManager->getPluginClass($record['field_type']); - if (empty($class)) { + try { + $class = $this->fieldTypeManager->getPluginClass($record['field_type']); + } + catch (PluginNotFoundException $e) { $config_id = $this->getPrefix() . $id; - throw new \RuntimeException("Unable to determine class for field type '{$record['field_type']}' found in the '$config_id' configuration"); + throw new PluginNotFoundException($record['field_type'], "Unable to determine class for field type '{$record['field_type']}' found in the '$config_id' configuration", $e->getCode(), $e); } $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']); } diff --git a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php index 565fa4e6f74963ba98a7859025d02969e1f01f9b..39560ad13c6ec2bd78fdebf276439a7b407c8123 100644 --- a/core/lib/Drupal/Core/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php @@ -167,8 +167,7 @@ public function getPreconfiguredOptions($field_type) { * {@inheritdoc} */ public function getPluginClass($type) { - $plugin_definition = $this->getDefinition($type, FALSE); - return $plugin_definition['class']; + return $this->getDefinition($type)['class']; } } diff --git a/core/lib/Drupal/Core/Field/FieldTypePluginManagerInterface.php b/core/lib/Drupal/Core/Field/FieldTypePluginManagerInterface.php index d937aabd446d507acd09d1f9526d17c0b4723dd7..dd5e9390ae4ca97aed5ad86bcbb205dd7eaf8d1d 100644 --- a/core/lib/Drupal/Core/Field/FieldTypePluginManagerInterface.php +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManagerInterface.php @@ -112,6 +112,9 @@ public function getPreconfiguredOptions($field_type); * * @return string * Field type plugin class name. + * + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + * Thrown if the field type plugin name is invalid. */ public function getPluginClass($type); diff --git a/core/modules/field/src/FieldStorageConfigStorage.php b/core/modules/field/src/FieldStorageConfigStorage.php index 6bd22c80fccf67b15ba55a9d05dcba933545d41f..c3b9445a48aad034ad80781d4a3614807e692019 100644 --- a/core/modules/field/src/FieldStorageConfigStorage.php +++ b/core/modules/field/src/FieldStorageConfigStorage.php @@ -2,6 +2,7 @@ namespace Drupal\field; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Config\Entity\ConfigEntityStorage; @@ -158,10 +159,12 @@ public function loadByProperties(array $conditions = []) { */ protected function mapFromStorageRecords(array $records) { foreach ($records as $id => &$record) { - $class = $this->fieldTypeManager->getPluginClass($record['type']); - if (empty($class)) { + try { + $class = $this->fieldTypeManager->getPluginClass($record['type']); + } + catch (PluginNotFoundException $e) { $config_id = $this->getPrefix() . $id; - throw new \RuntimeException("Unable to determine class for field type '{$record['type']}' found in the '$config_id' configuration"); + throw new PluginNotFoundException($record['type'], "Unable to determine class for field type '{$record['type']}' found in the '$config_id' configuration", $e->getCode(), $e); } $record['settings'] = $class::storageSettingsFromConfigData($record['settings']); } diff --git a/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php b/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php index ecaa729821e308561111ca2675dd4b870c824e29..6a230f5f0de628418e7136083ac561fb9650f139 100644 --- a/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php +++ b/core/tests/Drupal/KernelTests/Core/Field/FieldMissingTypeTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Field; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\entity_test\Entity\EntityTestMulRev; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -60,7 +61,7 @@ protected function setUp() { * @see \Drupal\field\FieldStorageConfigStorage::mapFromStorageRecords() */ public function testFieldStorageMissingType() { - $this->expectException(\RuntimeException::class); + $this->expectException(PluginNotFoundException::class); $this->expectExceptionMessage("Unable to determine class for field type 'foo_field_storage' found in the 'field.storage.entity_test_mulrev.{$this->fieldName}' configuration"); $entity = EntityTestMulRev::create([ 'name' => $this->randomString(), @@ -80,7 +81,7 @@ public function testFieldStorageMissingType() { * @see \Drupal\field\FieldConfigStorageBase::mapFromStorageRecords() */ public function testFieldMissingType() { - $this->expectException(\RuntimeException::class); + $this->expectException(PluginNotFoundException::class); $this->expectExceptionMessage("Unable to determine class for field type 'foo_field' found in the 'field.field.entity_test_mulrev.entity_test_mulrev.{$this->fieldName}' configuration"); $entity = EntityTestMulRev::create([ 'name' => $this->randomString(),