Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295283

EntityFieldManager::getFieldDefinitions silently accepts non-existing bundles

$
0
0

Trivia question: what's the difference between the return values of these to calls?

// Try to get field definitions of a non-existing bundle of the "node" entity type.
\Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'non_existing');
// Try to get field definitions of the "article" bundle of a non-existing entity type.
\Drupal::service('entity_field.manager')->getFieldDefinitions('non_existing', 'article');

Answer: while the second call throws an exception ("The non_existing entity type does not exist."), the first will happily oblige and return an array of all base fields of the node entity type. This is a problem for developers because it means that a small typo in the machine name of a bundle will remain unnoticed. (In my case, it took several hours to find out why my migration was running without errors, but field values were not saved on my paragraph entities.)

Proposed solution: throw an exception when the bundle does not exist, similar to what ContentEntityStorageBase::createWithSampleValues does.


Viewing all articles
Browse latest Browse all 295283

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>