A) I anticipate that contrib modules will commonly want to override \Drupal\Core\TypedData\TypedData::setValue()
B) Within Drupal core modules, this is a common enough task :-
\Drupal\Core\Field\FieldItemBase:setValue()
\Drupal\Core\TypedData\Plugin\DataType\Binary::setValue()
\Drupal\Core\TypedData\Plugin\DataType\ItemList::setValue()
\Drupal\Core\TypedData\Plugin\DataType\Language::setValue()
\Drupal\Core\TypedData\Plugin\DataType\Map::setValue()
Speaking constructively, core's consistency in approach to overriding this function is patchy. I would like contrib to be better.
This is in part due to the evolving documentation, and I want to improve the guidance regarding an exception.
BOTH
\Drupal\Core\TypedData\Plugin\DataType\Language::setValue()
\Drupal\Core\TypedData\Plugin\DataType\Map:setValue
throw \InvalidArgumentException when appropriate.
It is a simple 2 line fix.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | throw-2.patch | 622 bytes | martin107 |
| #2 | interdiff-0-2.txt | 656 bytes | martin107 |
| throw-0.patch | 623 bytes | martin107 |
Comments
Comment #1
jhodgdonThanks! This seems like a good idea.
The documentation has an extra space after @throws though.
Comment #2
martin107 commentedAh my mistake, fixed. Thanks
Comment #3
martin107 commentedComment #4
jhodgdonThat looks fine to me, thanks!
Comment #5
alexpottCommitted cf4cc20 and pushed to 8.x. Thanks!