[#787] Fixed isBaseField() to include computed base fields.#303
[#787] Fixed isBaseField() to include computed base fields.#303AlexSkrypnyk merged 1 commit intomasterfrom
isBaseField() to include computed base fields.#303Conversation
📝 WalkthroughWalkthroughThe changes refactor entity field manager access in Drupal8 core by introducing a centralized helper method and expand field type detection to include base field definitions. A new comprehensive PHPUnit test suite validates the refactored methods using mocked dependencies. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Relates to jhedstrom/drupalextension#787
Summary
isBaseField()previously usedgetFieldStorageDefinitions()to look up base fields, which only returns base fields that have field storage (i.e. non-computed ones). Computed base fields — such asmoderation_stateprovided by the Content Moderation module — are returned only bygetBaseFieldDefinitions()and were therefore silently excluded, causing them to be ignored when creating entities.The fix switches
isBaseField()to usegetBaseFieldDefinitions()directly.getEntityFieldTypes()is also updated to merge base field definitions into the field list when$base_fieldsis non-empty, ensuring computed base fields can be resolved to their type. BothisField()andgetEntityFieldTypes()are refactored to use a new protectedgetEntityFieldManager()helper, which removes duplicated\Drupal::service()calls and makes the class more testable.Changes
src/Drupal/Driver/Cores/Drupal8.phpisBaseField(): switched fromgetFieldStorageDefinitions()togetBaseFieldDefinitions()so computed base fields are recognised.getEntityFieldTypes(): mergesgetBaseFieldDefinitions()into the field list when$base_fieldsis non-empty, allowing computed base fields to be included in the result.getEntityFieldManager()protected helper — replaces three inline\Drupal::service('entity_field.manager')calls and enables unit testing without a full Drupal bootstrap.tests/Drupal/Tests/Driver/Drupal8FieldMethodsTest.php(new)isBaseField(),isField(), andgetEntityFieldTypes()with data providers.TestDrupal8Coresubclass that injects a mockEntityFieldManagerInterface, avoiding a full Drupal bootstrap.FieldStorageConfigstub to satisfyinstanceofchecks.Before / After
Summary by CodeRabbit
Tests
Refactor