Problem/Motivation

While working on #3189481: [Meta] Add source plugin documentation to the codebase, I discovered that d6/ViewMode source plugin uses targetEntityType constant to calculate migration dependencies. I wanted to document this constant, but noticed that DrupalSqlBase does something similar, but it takes entity_type constant instead.

Proposed resolution

We can simplify d6/ViewMode plugin by delegating dependency calculation to parent DrupalSqlBase class.
It requires renaming constant from targetEntityType to entity_type.

It might look like a breaking change, but I don't see how it hurts existing migrations. If someone copied this file and made a custom migration, I suspect that node module is already enabled on the destination website.

Remaining tasks

Review, commit.

Issue fork drupal-3206932

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

Matroskeen created an issue. See original summary.

matroskeen’s picture

Issue summary: View changes
Status: Active » Needs review
quietone’s picture

Such a lovely find! And I agree with the solution.

Just to be clear, this could be done without changing the yml file by adding this

    if (isset($this->configuration['constants']['targetEntityType'])) {
      $this->addDependency('module', $this->entityTypeManager->getDefinition($this->configuration['constants']['targetEntityType'])->getProvider());
    }

to DrupalSqlBase::calculateDependencies. That just allows the d6_view_modes.yml to define targetEntityType in the constants in the yml. There is nothing gained by keeping that constant name.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

Meant to make this RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

What about any custom migrations using this plugin? I think we need to deprecate and tell people to update the migration. I.e do something like:

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    $this->dependencies = parent::calculateDependencies();
    if (isset($this->configuration['constants']['targetEntityType'])) {
      @trigger_error('The constant targetEntityType is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Use entity_type instead. See CR', E_USER_DEPRECARTED);
      $this->addDependency('module', $this->entityTypeManager->getDefinition($this->configuration['constants']['targetEntityType'])->getProvider());
    }
    return $this->dependencies;
  }
matroskeen’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Sometimes I feel like we're overcomplicating things trying to catch those edge cases, but I agree it's better safe than sorry.
Added a draft change record (https://www.drupal.org/node/3208135) and deprecation notice as suggested in #6.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

@alexpott, thanks. As Matroskeen says better to be safe than sorry.

I reviewed the latest changes to the patch and they restore the method and add the deprecation notice. I read the change record and made a few modifications for readability and shortened the title.

I think this is ready.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure that the BC layer is quite right here. See comment on the MR.

matroskeen’s picture

Status: Needs work » Needs review

I have some mixed feelings about the suggested change.

Wouldn't it break the migration if someone already has entity_type constant in custom migration for a different purpose?

quietone’s picture

The change alexpott suggests is needed for anyone with a configured migration. They won't have a constant 'entity_type' on the row and that is what calculateDependencies() expects.

matroskeen’s picture

It would work on both cases, because we had this in child class:

if (isset($this->configuration['constants']['targetEntityType'])) {
  $this->addDependency('module', $this->entityTypeManager->getDefinition($this->configuration['constants']['targetEntityType'])->getProvider());
}

We just added a deprecation message to the existing method, nothing was really changed.

And we had this in parent class, which supports entity_type constant.

if (isset($this->configuration['constants']['entity_type'])) {
  $this->addDependency('module', $this->entityTypeManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider());
}

Anyway, I applied the suggested changes, but I'd like to share my concerns about the following case:

Let's imagine someone defined entity_type constant for a different purpose, e.g. the value is 'foo'.
In this case, in calculateDependencies() we overwrite this constant with value specified in targetEntityType constant, which is 'bar', for example.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

@Matroskeen, sorry, my comment in #11 isn't right. It is true the parent uses the constant entity_type but in first BC version the dependency was calculated correctly.

Yea, not sure I like overwriting a constant in a configured migration, it could break some custom code. Much better to let any existing constant stay and warn the user, which is what the first BC version did. In that first version a configured migration using entityTargetType would trigger an error but allow both the calculation of dependencies and any custom code to continue to work as is. In the second version bad things could happen.

matroskeen’s picture

Status: Needs review » Reviewed & tested by the community

@quietone, thanks for confirming my assumptions.

I'm reverting the last commit and moving it back to "RTBC" per #8.

alexpott’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Fixed

If entity_type and entityTargetType are different then bad things are going to happen when we remove support for entityTargetType. But I guess the point is you can have that pain when we remove the deprecation and at least you've been warned it is going to happen.

Committed and pushed bd2a1eabe0 to 9.3.x and 577be8956e to 9.2.x. Thanks!

  • alexpott committed bd2a1ea on 9.3.x
    Issue #3206932 by Matroskeen, quietone, alexpott: Rename...

  • alexpott committed 577be89 on 9.2.x
    Issue #3206932 by Matroskeen, quietone, alexpott: Rename...

matroskeen’s picture

Thanks!

Closed the merge request and published a change record.

Status: Fixed » Closed (fixed)

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