Problem/Motivation

The ed11y_page table contains incorrect or missing entity_id values, incorrect entity_type and incomplete page_path values.

This probably doesn't matter for most people, but I'm trying to build some custom views that display editoria11y data related to groups (group module), and because the entity_id and entity_type are wrong, adding the relationship is currently impossible.

For example, this is what I see in the ed11y_page table:

incorrect data in table

The actual correct data for these entities is:

correct data example

Steps to reproduce

I believe this all stems from editoria11y_page_attachments() in editoria11y.module.

This bit conflates entity types with bundles, which are two different things:

$entity = $candidate;
              // Get entity type label via the bundle entity (works for any
              // content entity type, not just nodes).
              $bundle_type_id = $entity->getEntityType()->getBundleEntityType();
              if ($bundle_type_id) {
                $bundle_storage = Drupal::entityTypeManager()->getStorage($bundle_type_id);
                if ($bundle_storage) {
                  $bundle_entity = $bundle_storage->load($entity->bundle());
                  if ($bundle_entity) {
                    $entity_type = $bundle_entity->label();
                  }
                }
              }

In my case it's the different between getting "group" which is an entity type and getting "About", which is one of several group entity bundles.

I'm not sure yet how the entity_id and page_path are wrong/incomplete. I suspect the page_path does not take path aliases into account.

This is not a problem confined to the group module. User entities also have no entity_ids:

missing entity_id for user entities

Environment details for bug reports
  • Drupal version: 10.6.7
  • CSA submodule installed: N
  • Exports submodule installed: N

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

maskedjellybean created an issue. See original summary.

itmaybejj’s picture

Assigned: Unassigned » itmaybejj
maskedjellybean’s picture

StatusFileSize
new38.94 KB

MR opened. It appears we can fix the entity_type, entity_id and page_path just by changing that one bit of code.

However, this should not be merged as is, because it causes duplicate data. Because the entity_id is now correct, the previous row associated with the pid and previous entity_id (0) is not found, and a new row with the correct data is created:

correct data after changes in MR with incorrect old data

maskedjellybean’s picture

You'll also have to decide whether you want entity_type to be the actual machine name of the entity or a human readable version that is used elsewhere in the code ("Entity: User"). Using the machine name means you can easily load the entity if need be. If there's a need to display "Entity: User" somewhere, can't that be done during render somewhere?

itmaybejj’s picture

I'm going to have to really, really dig into this to get you some concrete answers and confirm your MR will work across the board; this part of the code is fantastically prone to conflicts with other modules and custom entities that do not quite fully implement various interfaces, so I am always juggling accuracy and completeness with "not crashing in production." I'm going to try to replicate your setup to see if I can trip the null entity_id; this is the first I've seen that, and I rely on entity_id in a lot of the dashboard code, so it needs to be right.

Up until now I have used route_name + entity_id for Views reference plugins, and only intended entity_type as a human readable bundle label for the most precise bundle, as a filter for the dashboard. Thus all the various fallbacks, for entities that don't have a traditional bundle.

Page path should be pulling whatever the entity itself calls canonical. That may or may not be aliased.

One question to quick confirm before I dig in: do you see all these issues with freshly syncing data in the latest 3.x release with a fresh module install, or is there migrated 2.x data in your tables conflating things?

If I get all this replicated and working, I should be able to merge a version of your fix and layer on an update hook that runs a batch correction for affected rows based on path and route name.

maskedjellybean’s picture

StatusFileSize
new42.71 KB

This is migrated data from 2.x where this issue existed in 2.x and continues in 3.x. Actually part of the reason I upgraded to 3.x was to see if it fixed this. Before making any changes I refreshed some pages where the entity_id was missing or incorrect, did some step debugging, checked the database rows and found that the issue was the same as 2.x. So I don't think the issue is really related to migrated data from 2.x.

The problem with the bit of code for group compatibility at least is that the path to group content is /group/{GROUP_ID}/content/{GROUP_CONTENT_ID}. Since the code was grabbing the first section of the path and assuming that was the entity type, it was finding "group" and not "group_content".

I think it's safer to get the entity type from the route name which we already have if the route name starts with "entity." and ends with ".canonical". I've never seen an entity canonical route that didn't follow this pattern: entity.ENTITY_TYPE.canonical

This way we're not looking at the route parameters and trying to predict what they may be for the entity type.

BTW I see this change fixes missing entity_id for users as well (after adding an empty H1 to user.html.twig and viewing a user):

correct user entity data after changes

itmaybejj’s picture

That makes sense. I'll get Group installed and added to my unit tests in the next release with this so I don't regress in the future.

  • itmaybejj committed 1ddb7a4a on group-compatibility
    fix: #3590757 Incorrect entity_id, entity_type and page_path in...

  • itmaybejj committed 292cfd03 on group-compatibility
    fix: #3590757 Add view relationships
    
itmaybejj’s picture

I have not yet tested my new merge request for this so don't try it in production, but if you are up for helping me with testing, since you have real data and I just have a sandbox, in theory it should:

  1. Correctly identify entity/user IDs when nested inside group IDs in the page data drupalSettings, allowing the API to work for newly crawled pages.
  2. Add an update hook based on one of the CSA batch dashboard update scripts that rediscovers IDs for existing rows based on the stored path or alias if possible, and discards corrupt rows, which block correcting the entity_id. This will discard MOST rows for you, but the rows were useless anyway (wrong path, not matching PID for dismissals). CSA has a manual crawler that is rarely useful but designed for just this situation -- I think my recommended recovery for Groups module users will be to run the update hook, then use a CSA trial and run the crawler to repopulate their dashboard. They can then immediately uninstall CSA if they are not interested in the rest of its features.
  3. Create turnkey Views relationships you can use to map between results and nodes/users/terms by Group membership. Generating turnkey relationships via Views plugins rather than in the GUI means I can map by entity ID and route name, and don't need to add an entity type machine name column; I just have to make sure I add all the relationships you need in code.

  • itmaybejj committed 5253b897 on group-compatibility
    fix: #3590757: Drop irrecoverable rows
    
itmaybejj’s picture

Title: Incorrect entity_id, entity_type and page_path in ed11y_page table » Group module compatibility: incorrect entity_id, entity_type and page_path in ed11y_page table
Component: Bugs » Conflicts with other modules

  • itmaybejj committed 18c50f0a on 3.0.x-dev
    fix: #3590757 Add support for Groups module.
    
itmaybejj’s picture

Status: Active » Needs review
itmaybejj’s picture

Status: Needs review » Fixed

OK I tagged 3.0.4 with the fixes.

Contact me if you want a year of CSA for helping test.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

maskedjellybean’s picture

Wow this is more than I ever expected! Thanks!

I'm sorry for disappearing on you. I want to be helpful and test this but I had my head down making group compatible views and we went different directions. TBH it might be for the best because the group setup on my site is a bit custom to say the least, which I'm sorry I didn't factor in when I opened this issue. Due to decisions made years ago without me, we render the related node on the group content route (we only allow a node to relate to one group). With this setup I doubt I can fairly test your solution. What I can say is that I was able to make my group compatible views (which I started by copying the ones provided by editoria11y) accept a group id as contextual argument and I was able to create the necessary relationships without additional code. But this was only after I patched editoria11y so that a group_content page has entity_type "node" in ed11y_page table and entity_id is the node id. I realize that is far too custom a patch to contribute back. I wish we had a normal group setup, because it would be great to contribute my custom module (with a controller, local task and group level permission so group members can access the report at /group/GROUP_ID/reports/editoria11y), but I'm afraid all it would do is cause more confusion.

If I can find a bit more time I'll see if I can apply your solution and see how it plays with this unique setup, but of course that won't be a good test of a normal group setup.

itmaybejj’s picture

Ahh fair enough.

If you want to convert the code in your patch to something less fragile, you may want to look at the new editoria11y_alter_config hook. That lets you read and modify any of the page data from the dot-module file (like entity type and ID) on the fly.

I needed a hook for role-based split config and figured other people might want it too.

Status: Fixed » Closed (fixed)

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