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.

CommentFileSizeAuthor
#2 throw-2.patch622 bytesmartin107
#2 interdiff-0-2.txt656 bytesmartin107
throw-0.patch623 bytesmartin107

Comments

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! This seems like a good idea.

The documentation has an extra space after @throws though.

martin107’s picture

StatusFileSize
new656 bytes
new622 bytes

Ah my mistake, fixed. Thanks

martin107’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

That looks fine to me, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed cf4cc20 and pushed to 8.x. Thanks!

  • alexpott committed cf4cc20 on 8.x
    Issue #2297631 by martin107: Nudge contrib into overriding \Drupal\Core\...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.