Problem/Motivation

#3193254: using dynamic_entity_reference brings in triggers and uninstalling does not get rid of them

Steps to reproduce

Proposed resolution

Clone functionality as suggested by @eiriksm in #3346793: Version 2.0.0-alpha1 is incompatible with Drupal 9.5.4.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#27 linkchecker.patch1.84 KBlee.cocklin
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

C-Logemann created an issue. See original summary.

c-logemann’s picture

Title: Remove dependency of Dynamic Entity Reference (DER) » Remove Dynamic Entity Reference (DER) dependency

joelpittet made their first commit to this issue’s fork.

joelpittet’s picture

Status: Active » Needs review

I'm setting to Needs Review because I did a very rough WIP for an idea on how we could do this.

The gist of the idea:
Instead of storing the entity_id field as a DER, just store an internal link and derive the entity data from loading the internal path (kind of like the menu_link_content module in core does)

That way even if the entity has been deleted we would have a reference to where it came from.

Does this idea gel with the maintainers?

joelpittet’s picture

The failures are expected BTW, I just need some confirmation on the approach before I tackle those.

eiriksm’s picture

I am very open and positive to this. The implementation details can be tweaked too I guess, but I can't see why this would not cover at least most of the usecases. One aspect that I do not know if works or not is if an entity type does not actually have a canonical URL. Is that possible or common? If I created a custom entity type , could I opt to not have it have a canonical URL?

c-logemann’s picture

First of all: @joelpittet’s thank you for moving forward on this.

I currently have no time to review because of customer projects. But in one project I will soon create at least one entity type which don't need a canonical route definition. This makes sense if an entity is just for storing data or its managed via other entities. A good example is the paragraphs module and its entity type "paragraph". Currently there is no "links" section defined.

Edit: improved text and added link to "paragraphs" module and just realized that the entity type is different as the module name so also corrected this above.

joelpittet’s picture

I guess for the paragraphs module (and others like it, storage module for example).

You'd probably want the host entity URL anyway, right? Currently the URL is shown (when possible) on the report page.

eiriksm’s picture

Sure but I was referring to being able to load (or save for that matter) the entity you want to check from the URL 🤓

joseph.olstad made their first commit to this issue’s fork.

quadrexdev’s picture

I have started working on this and I hope to finish it within the next few days

quadrexdev’s picture

Okay, so I added two base fields: parent_entity_id and parent_entity_type_id instead of using DER field or a link field.

Adding two base fields for storing entity_type_id and entity_id looks like a simpler and more reliable solution for me.

I'll spend some more time testing this one. If someone else can test it and/or provide some feedback - feel free :)

abramm’s picture

Status: Needs review » Needs work

I checked the MR, added a minor suggestion.

quadrexdev’s picture

Status: Needs work » Fixed

Committed on 2.0.x, thanks everyone for your contribution!

c-logemann’s picture

I didn't found the time to test and code but I want to thank everyone involved to solve this.

joseph.olstad’s picture

Nice work on this! Very good to remove der if it's not needed!

Status: Fixed » Closed (fixed)

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

frederikvho’s picture

I just wanted to add that I received a logical error when trying to update this module, because the removed dependency is still installed in the active configuration upon deploy. This causes drush updb to fail. This is normal Drupal deploy behavior and cannot be prevented afaik.

 [error]   (Currently using Missing or invalid module The following module is marked as installed in the core.extension
configuration, but it is missing:
 * dynamic_entity_reference

I solved this by doing two deploys:
First composer require the dependency that was removed in the latest update.
The rest of the flow can stay the same, so:
dependency should be removed from core.extension.yml file
Then deploy.
Only difference is Drush updb won't fail this time around. Because you will have put the dependency back in place separately.

For the next deploy you can remove the required dependency, once and for all.

Both this updb error and my solution seem logic to me, keeping the Drupal deploy strategy in mind, so I didn't see the need to create a new ticket. I just wanted to put this out there in case other developers struggle with.

nmorin’s picture

@frederikvho - Thanks for your comment and work-around! I am seeing the same thing running drush updb after upgrade to 2.1.0-alpha1.

rp7’s picture

Thank you for the efforts made here.

Just FYI: I'm in the process of upgrading the Linkchecker module on my project and running against some issues related to Views. I have a View listing linkchecker links that also displays (per linkchecker link) a few fields of the linkchecker link's related entity (e.g. the entity the link was made in).

Turns out the Dynamic Entity Reference module has built-in functionality (dynamic_entity_reference_field_views_data()) that makes this possible. Looks like this functionality is completely lost now.

joseph.olstad’s picture

We've been using linkchecker 2.1.0-alpha1 in production with a few patches, haven't noticed the regression mentioned in #22, not sure I understand what that is. We did a bit of a spike on linkchecker this week to add in a "Check links" button #3426268: Allow to check link status on demand , we are continuing to evaluate use case scenarios as we move forward and will report any issues we find or create patches as needed.

rp7’s picture

@jospeh.olstad

not sure I understand what that is

For example: you have a link field on content type Article. You enable linkchecker for that particular field. On the linkchecker broken links report (view), you also want to display the article's title besides each checked link. For that, in Views, you'll need a relationship from the linkchecker link entity table to the node table. The ability to add this relation to your view is something that the Dynamic Entity Reference module provided out of the box.

For anyone looking to restore this functionality, I constructed this piece of code which seems to do the job:

/**
 * Implements hook_views_data_alter().
 */
function mymodule_views_data_alter(array &$data) {
  if (!empty($data['linkchecker_link']) && empty($data['linkchecker_link']['node__entity_id']['relationship'])) {
    $entity_type = \Drupal::entityTypeManager()->getDefinition('linkcheckerlink');
    $target_entity_type = \Drupal::entityTypeManager()->getDefinition('node');

    $t_args = [
      '@origin_label' => $entity_type->getLabel(),
      '@target_label' => $target_entity_type->getLabel(),
      '@field_name' => 'parent_entity_id',
      '@type' => 'base field',
    ];

    $data['linkchecker_link']['node__entity_id']['relationship'] = [
      'title' => new TranslatableMarkup('@field_name to @target_label entities', $t_args),
      'label' => new TranslatableMarkup('@field_name: @target_label', $t_args),
      'group' => $entity_type->getLabel(),
      'help' => new TranslatableMarkup('References to @target_label entities referenced by @field_name @type on @origin_label entities.', $t_args),
      'id' => 'standard',
      'base' => 'node_field_data',
      'entity type' => $target_entity_type->id(),
      'base field' => $target_entity_type->getKey('id'),
      'relationship field' => 'parent_entity_id',
      'extra' => [
        [
          'left_field' => 'parent_entity_type_id',
          'value' => 'node',
        ],
      ],
    ];
  }
}

Not saying this is something that Linkchecker should offer out of the box (although I think it could come in very handy for some users), just leaving it out here for people running against similar issues.

rp7’s picture

I found another issue by the way, but this is something that should be fixed in the Dynamic Entity Reference module.

I upgraded to Linkchecker 2.1.x (with the Dynamic Entity Reference field removed), and was receiving fatal errors about queries trying to write to the entity_id__target_id_int column in the linkcheckerlink table. Appears DER doesn't (always) automatically remove its database triggers. See #2766189: Fix IntColumnHandler::delete for more info and a potential fix.

c-logemann’s picture

@rp7
> Appears DER doesn't (always) automatically remove its database triggers

Because DER is using database triggers which are more complicate to handle especially in common managed hosting setups is the main reason why we wanted to get rid of it.

If there is a need for more views integration we can also implement this in linkchecker. Please open a follow up Issue for this and other missing features and merge requests are always welcome.

lee.cocklin’s picture

StatusFileSize
new1.84 KB

@rp7

Thanks for this! I applied it as a patch. I really think this should be integrated into the module.

**EDIT I realized after the fact the hook was already declared in a .inc file so I recreated the patch and uploaded it into the feature request https://www.drupal.org/project/linkchecker/issues/3539894

lee.cocklin’s picture

@rp7 @c-logemann

I created a feature request ticket: https://www.drupal.org/project/linkchecker/issues/3539894

joseph.olstad’s picture

I modified #27 and added a merge request for #3539894: Add parent entity relationship

patch file