Problem/Motivation
\Drupal\Core\Field\FieldTypePluginManager::getPluginClass()
calls getDefinition()
with $exception_on_invalid = FALSE
for.. historical reasons. It was initially introduced like that in #2293773: Field allowed values use dots in key names - not allowed in config probably because field widgets and formatters were also using $exception_on_invalid = FALSE
, but the difference is that those two plugin types can fall back to a default widget/formatter, while a field type has no fallback.
Proposed resolution
Make \Drupal\Core\Field\FieldTypePluginManager::getPluginClass()
throw the standard plugin not found exception.
This also fixes PHP 7.4 compatibility problems because the return statement of getPluginClass()
will never be reached with an empty $plugin_definition
variable.
Remaining tasks
Review.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Release notes snippet
Nope.
Comment | File | Size | Author |
---|---|---|---|
#9 | interdiff-9.txt | 1.19 KB | amateescu |
#9 | 3095895-9.patch | 5.64 KB | amateescu |
#7 | interdiff-7.txt | 3.96 KB | amateescu |
#7 | 3095895-7.patch | 5.02 KB | amateescu |
#2 | 3095895.patch | 4.25 KB | amateescu |
Comments
Comment #2
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThis should do it.
Comment #3
alexpottThe exception is way way less helpful though. Imo we should preserve the helpful exception somehow. Catching and re-throwing come to mind.
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@alexpott I considered that when writing the patch, but the current exception only works for configurable fields and not for base fields, so I think that's also confusing rather than helpful. In turn, with the current patch, we get the standard plugin exception that people are used to see when dealing with any kind of plugin..
Comment #5
alexpottWell we're mapping from storage records so I'm not sure when you'd see the current exception for base fields? I.e. I think it is okay to catch and rethrow in :: mapFromStorageRecords() to improve the exception message.
Comment #6
hchonovComment #7
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@alexpott, ok, let's do that :)
Comment #8
alexpott+1 to updating the exception types to the more meaningful PluginNotFoundException.
Let's update the interface docs with an @throws...
For example:
I'd also be tempted to make this a one-liner. Ie.
return $this->getDefinition($type)['class'];
Comment #9
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedSure, make sense!
Comment #10
alexpottThanks @amateescu - this looks good to me. Will leave for someone else to rtbc so I can commit.
Comment #11
hchonovThere is simply nothing to add.
Comment #12
alexpottCommitted and pushed a6477d5904 to 9.0.x and d5e903d1bd to 8.9.x. Thanks!
Comment #15
alexpottAs this is part of the PHP7.4 critical cherry-picked this back to 8.8.x. @catch +1'd the backport.