fix: adjusted the bundle inclusion check for paragraphs

Summary of Changes

This commit addresses an issue with paragraph reference bundle handling in the cms_content_sync module. The primary focus is on correctly identifying which bundles are allowed in entity reference fields, particularly for paragraph references where bundles can be excluded rather than included.

Files Modified

  1. cms_content_sync.module

    • Updated the _cms_content_sync_display_entity_type_differences_recursively function to use the new FieldHelper service for retrieving target bundles instead of directly accessing field settings
  2. cms_content_sync.services.yml

    • Added a new service definition for the FieldHelper class:
    cms_content_sync.field_helper:
      class: Drupal\cms_content_sync\Helper\FieldHelper
  3. src/Controller/FlowControllerSimple.php

    • Replaced direct access to field settings with calls to the FieldHelper service
    • Simplified code that was previously iterating over target bundles
  4. src/Form/FlowForm.php

    • Updated the form to use the FieldHelper service for retrieving target bundles
    • Modified the loop that generates the bundle list in the UI
  5. src/Helper/SimpleFlowSetupHelper.php

    • Updated the code to use the FieldHelper service for retrieving taxonomy term reference target bundles
  6. src/Plugin/EntityReferenceHandlerBase.php

    • Simplified code by replacing multiple checks for target bundles with a single call to the FieldHelper service
  7. src/Plugin/FieldHandlerBase.php

    • Added a dependency on the FieldHelper service
    • Added a new protected property $fieldHelper to store the service
    • Updated the constructor and create method to inject the FieldHelper service
    • Added a new helper method getFieldTargetBundles() that uses the FieldHelper service
    • Updated code that was directly accessing field settings to use the new helper method
  8. src/Plugin/cms_content_sync/field_handler/DefaultEntityReferenceHandler.php

    • Replaced complex target bundle detection code with a call to the new getFieldTargetBundles() method

Files Added

  1. src/Helper/FieldHelper.php
    • Created a new helper class with a method getEntityReferenceFieldAllowedTargetBundles() that:
      • First checks for direct target_bundles setting
      • Falls back to checking handler_settings.target_bundles
      • Handles the special case for paragraph fields where bundles can be excluded rather than included
      • Properly handles the negate setting in paragraph reference fields
      • Returns an array of allowed target bundle IDs

Key Improvements

  1. Centralized Bundle Detection Logic: All code for determining which bundles are allowed in an entity reference field is now in one place, making it easier to maintain.
  2. Support for Excluded Bundles: The code now correctly handles paragraph reference fields that use the "exclude" option rather than the "include" option for bundle selection.
  3. Consistent API: All parts of the module now use the same method to retrieve target bundles, ensuring consistent behavior.
  4. Code Simplification: Removed duplicate code that was performing similar checks in multiple places.

This commit fixes an issue where paragraph reference fields that used the "exclude" option for bundle selection weren't being handled correctly, which could lead to incorrect synchronization behavior for paragraph entities.

Edited by Daniel Popov

Merge request reports

Loading