Comments

narendraR created an issue. See original summary.

narendrar’s picture

StatusFileSize
new5.99 KB

Patch attached

omkar.podey’s picture

Issue tags: -Needs manual testing
StatusFileSize
new250.61 KB
new357.41 KB
new134.51 KB
new215.99 KB

Manual testing done , the patch successfully migrates linkit data form d7 to d9.
Attached screenshots.

narendrar’s picture

StatusFileSize
new7.12 KB
new4.26 KB

Code updated with necessary migration dependencies

wim leers’s picture

+++ b/src/Plugin/migrate/process/LinkitProfilesMatchers.php
@@ -76,7 +82,24 @@ class LinkitProfilesMatchers extends ProcessPluginBase implements ContainerFacto
+          if ($matcher_key == 'entity:comment') {
+            $lookup_results = [];
+            foreach ($check_bundles_array as $comment_bundle) {
+              $value = preg_replace('/comment_node_/', NULL, $comment_bundle);
+              $migration = 'd7_comment_type';
+              $lookup_result = $this->migrateLookup->lookup($migration, [$value]);
+              $lookup_results[] = empty($lookup_result) ? NULL : reset($lookup_result[0]);

We also need a migrate lookup for d7_node_type, because they could be renamed from the source to the destination.

narendrar’s picture

StatusFileSize
new1.9 KB
new7.76 KB

Thanks Wim for review.
Attached is the updated patch.

omkar.podey’s picture

Issue tags: -Needs tests
StatusFileSize
new16.85 KB
new9.09 KB
wim leers’s picture

Status: Active » Needs work

Looking good! I have a bunch of coding style-related remarks for you, @omkar.podey 😅🤓

  1. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    $entityTypeManager = $this->container->get('entity_type.manager');
    

    You can make this a class-level property.

    See \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest for an example.

    Then you can do $this->entityTypeManager. That is slightly cleaner.

  2. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    /**
    +     * Initial test for verifying if new profile is loaded.
    +     */
    

    We never use /* … */ style comments in function bodies. Can you convert these to //-style comments? 🤓🙏

  3. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    $this->assertEquals(2, count($profile_types), 'Found two Linkit profile.');
    

    Nit: $this->assertCount(2, $profile_types); would be even simpler!

  4. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    /** @var \Drupal\linkit\Entity\Profile $linkitProfile */
    +    $linkitProfile = $configStorage->load('test_migration');
    

    Nit: we use camelCased class method and class property names, but underscored names everywhere else. That also means all variable names in function bodies should use underscores, so this would become $linkit_profile.

  5. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    }
    +
    +  }
    

    Übernit: we don't allow a newline just before the closing brace.

  6. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    $this->assertEquals(TRUE, $config['settings']['group_by_bundle']);
    

    Nit: $this->assertTrue() would be simpler.

  7. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    $this->assertEquals('[node:title]', $config['settings']['metadata']);
    

    Nit: assertEquals() is an equality (==) check. It's always safer to be stricter (===), and hence to use assertSame() whenever possible.

  8. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,122 @@
    +    $this->assertEquals([], $config['settings']['bundles']);
    +
    +  }
    

    Same here.

omkar.podey’s picture

Status: Needs work » Needs review
StatusFileSize
new16.77 KB
new4.05 KB

Updated as per Wim's review .

wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/migrate/process/LinkitProfilesMatchers.php
    @@ -0,0 +1,142 @@
    +            $comment_lookup_results = [];
    +            foreach ($check_bundles_array as $comment_bundle) {
    +              $value = preg_replace('/comment_node_/', NULL, $comment_bundle);
    +              $migration = 'd7_comment_type';
    +              $lookup_result = $this->migrateLookup->lookup($migration, [$value]);
    +              $comment_lookup_results[] = empty($lookup_result) ? NULL : reset($lookup_result[0]);
    +            }
    +            if (!empty($comment_lookup_results)) {
    +              $matcher_value['bundles'] = $comment_lookup_results;
    +            }
    +            else {
    +              unset($matcher_value['bundles']);
    +            }
    

    I'd like to see this moved to a helper method, that'll make the code much easier to read.

  2. +++ b/src/Plugin/migrate/process/LinkitProfilesMatchers.php
    @@ -0,0 +1,142 @@
    +            $node_lookup_results = [];
    +            foreach ($check_bundles_array as $node_bundle) {
    +              $migration = 'd7_node_type';
    +              $lookup_result = $this->migrateLookup->lookup($migration, [$node_bundle]);
    +              $node_lookup_results[] = empty($lookup_result) ? NULL : reset($lookup_result[0]);
    +            }
    +            if (!empty($node_lookup_results)) {
    +              $matcher_value['bundles'] = $node_lookup_results;
    +            }
    +            else {
    +              unset($matcher_value['bundles']);
    +            }
    

    And this too should be moved to a helper method.

  3. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,120 @@
    +  public static $modules = [
    

    In newer versions of PHP this will yield an error, because this is an inherited class property we're overriding — and the parent one uses protected. We should use the same visibility here.

  4. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,120 @@
    +    $this->entityTypeManager = $this->container->get('entity_type.manager');
    

    Nit: it's great that we're assigning it like this, but protected $entityTypeManager is not specified like \Drupal\Tests\content_translation\Kernel\ContentTranslationHandlerTest::$entityTypeManager is.

  5. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,120 @@
    +      if ($config['id'] == "entity:node") {
    +        $this->nodeTest($config);
    +      }
    +      elseif ($config['id'] == "entity:file") {
    +        $this->fileTest($config);
    +      }
    +      elseif ($config['id'] == "entity:comment") {
    +        $this->commentTest($config);
    +      }
    

    Nit: these could use === checks 🤓

  6. +++ b/tests/src/Kernel/d7/LinkitProfilesMigrateTest.php
    @@ -0,0 +1,120 @@
    +    $this->assertSame([], $config['settings']['bundles']);
    +
    +  }
    ...
    +    $this->assertSame($images, $config['settings']['images']);
    +
    +  }
    ...
    +    $this->assertSame('[comment:title]', $config['settings']['metadata']);
    +
    +  }
    

    These still have the extraneous newline before the closing brace — let's remove them :)

omkar.podey’s picture

Status: Needs work » Active
StatusFileSize
new16.61 KB
new5.32 KB

Updated as per review .

omkar.podey’s picture

Status: Active » Needs review
wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/migrate/process/LinkitProfilesMatchers.php
    @@ -83,33 +83,10 @@ class LinkitProfilesMatchers extends ProcessPluginBase implements ContainerFacto
    +            $this->lookupBundles('d7_comment_type', $check_bundles_array, $matcher_value);
    ...
    +            $this->lookupBundles('d7_node_type', $check_bundles_array, $matcher_value);
    

    Nice! Deduplicated code! 🥳

  2. +++ b/src/Plugin/migrate/process/LinkitProfilesMatchers.php
    @@ -128,6 +105,29 @@ class LinkitProfilesMatchers extends ProcessPluginBase implements ContainerFacto
    +  /**
    +   * Helper function to Look up bundles and set / unset values.
    +   */
    +  protected function lookupBundles($migration, $check_bundles_array, &$matcher_value) {
    

    Missing docblock documenting the various parameters (@param) and return value (@return).

    Also missing typehints.

  3. +++ b/src/Plugin/migrate/process/LinkitProfilesMatchers.php
    @@ -128,6 +105,29 @@ class LinkitProfilesMatchers extends ProcessPluginBase implements ContainerFacto
    +    if (!empty($lookup_results)) {
    +      $matcher_value['bundles'] = $lookup_results;
    +    }
    +    else {
    +      unset($matcher_value['bundles']);
    +    }
    +  }
    

    Why modify $matcher_value by reference? When possible, avoid modifying by reference, and prefer return values. That makes it easier to understand, and also easier to test :)

omkar.podey’s picture

StatusFileSize
new17.1 KB
new2.59 KB

Updated as per review.

omkar.podey’s picture

Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Perfect! 🤩

johnwebdev’s picture

How can I easily test this manually?

wim leers’s picture

Apply this patch, install migrate_tools, then run drush migrate:import d7_linkit_profiles 😊

mark_fullmer’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

For some time now, as indicated by the Linkit project page, the 8.x-5.x branch of Linkit is not undergoing active development. It is also only compatible with unsupported versions of Drupal core (Drupal 8 and Drupal 9).

To help the maintainers of the Linkit module better steward tasks under active development, I'm going to mark this issue as closed (wontfix). Sites using 8.x-5.x can certainly continue to do so, but should make plans for updating to the latest supported version of Linkit.

Even better: Drupal core will soon provide link autocomplete suggestions in CKEditor similar to what this module does. Sites using or considering using Linkit should follow this core issue to evaluate whether they can use the core solution instead of Linkit. See feature differences below to compare what Linkit includes that will not initially be in Drupal core.

If this issue relates to a problem or feature request that is applicable to the latest supported version of Linkit, please create a new issue, associated with that branch, describing the bug or enhancement.

For participation and information in Linkit's roadmap, see #3345480: LinkIt Release Roadmap and Issue Prioritization.

Thanks, community, for you collaboration and consideration!