apigee-edge-drupal icon indicating copy to clipboard operation
apigee-edge-drupal copied to clipboard

Add magic get/setters for entityreferences (#948)

Open boobaa opened this issue 1 year ago • 8 comments

Closes #948.

boobaa avatar Oct 10 '23 16:10 boobaa

Thank you @boobaa for your contribution. We will review the PR and update.

divya-intelli avatar Oct 11 '23 07:10 divya-intelli

Also had to distinguish apigee baseFields: without doing that, /teams page was just a WSOD.

boobaa avatar Oct 11 '23 17:10 boobaa

Hi @boobaa I have checked the commits and files on the new installation. Before implementing the fix, as per @mxr576 steps to reproduce, the issue is WSOD Post applying the changes, we still see the WSOD following the same steps.

We cannot merge this as it does not solves the mentioned issue. It will need more further work and testing.

Thanks!

kedarkhaire avatar Nov 28 '23 13:11 kedarkhaire

Hi @boobaa We have performed the following tests to check the fix post appending your changes.

  1. Created a new API reference field in Teams creation form.
  2. Checked the create new entity if not avaiable option in the field settings page.
  3. Created a Team with new text in the entity reference field and submitted the team.
  4. WSOD was observed.

This led to the failure of manual test from my end. If there is any specific steps you tried to check the working state of code which gave you positive results please share with us, we will surely look into it.

Thanks!

kedarkhaire avatar Dec 14 '23 12:12 kedarkhaire

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (dc96b7d) 44.20% compared to head (b67f189) 44.20%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                3.x     #956   +/-   ##
=========================================
  Coverage     44.20%   44.20%           
  Complexity     3029     3029           
=========================================
  Files           341      341           
  Lines         11086    11086           
=========================================
  Hits           4901     4901           
  Misses         6185     6185           
Files Coverage Δ
src/Entity/FieldableEdgeEntityBase.php 76.58% <ø> (ø)

codecov[bot] avatar Dec 22 '23 06:12 codecov[bot]

Here's what I did for reproduction:

  1. Installed drupal-10.2.1 from scratch, with minimal profile + field_ui module.
  2. Installed drupal/apigee_edge-3.0.5 and configured it to use an organization on our OPDK server. Connection was successful.
  3. Navigated to /admin/config/apigee-edge/team-settings/fields and created a new Reference field for an API (product).
  4. Navigated to /admin/structure/block and placed the "Team switcher" block.
  5. Navigated to an already-existing team using this "Team switcher" block.
  6. Clicked Edit, typed an already-existing API (product) name to the just added field.
  7. Clicked "Save team".

Expected result: team getting saved properly, with the new field being displayed with the selected API (product).

Actual result without the patch: WSOD (The website encountered an unexpected error. Try again later.), with this in the logs:

Error: Call to a member function getValue() on null in Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate() (line 128 of /mnt/files/local_mount/build/web/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/ValidReferenceConstraintValidator.php).

Actual result with the patch: team got saved properly, with the new field displaying the selected API (product).

FTR, I ran composer require cweagans/composer-patches and added this to the extra section of my root composer.json to apply the patch:

        "patches": {
            "drupal/apigee_edge": {
                "Magic getters/setters support for fieldable Apigee entities - https://github.com/apigee/apigee-edge-drupal/pull/956": "https://patch-diff.githubusercontent.com/raw/apigee/apigee-edge-drupal/pull/956.patch"
            }
        }

Hope this helps.

boobaa avatar Jan 10 '24 18:01 boobaa

Hi @boobaa

Drupal version - 10.1.8 & 10.2.2 Apigee Edge 3.0.5 checked with Devportal latest version as well as on the Vanilla Drupal 10.2.2 version. As per the steps you shared we checked and just wanted to clear few points.

  • On point 3, when you are creating a new Reference field for an API, are you selecting this checkbox - Create referenced entities if they don't already exist
  • If yes, then on point 6, are you trying to create a new value in API reference field ?

The steps which you mentioned, in that case, we do not see any error/WSOD on the page without applying any patch.

Issue occurs when the above 2 points are performed. Just to be on the same page, can you tell us, if the code was checked with these 2 points ?

Thanks!

kedarkhaire avatar Jan 18 '24 08:01 kedarkhaire

Hi @kedarkhaire ,

as the customer does not want to litter their Apigee Edge with random API products when teams are getting created/edited, but only allow users to select from already-existing API products, those options are NOT enabled.

boobaa avatar Jan 19 '24 07:01 boobaa