Skip to content
Snippets Groups Projects
Unverified Commit a6477d59 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3095895 by amateescu, alexpott:...

Issue #3095895 by amateescu, alexpott: FieldTypePluginManager::getPluginClass() should throw an exception when called for a field type that doesn't exist
parent e3873ccd
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
......@@ -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']);
}
......
......@@ -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'];
}
}
......@@ -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);
......
......@@ -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']);
}
......
......@@ -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(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment