Support from Acquia helps fund testing for Drupal Acquia logo

Comments

n4r3n created an issue. See original summary.

n4r3n’s picture

This patch adds field migration plugin and related test-case.

huzooka’s picture

Very nice!

  1. +++ b/src/Plugin/migrate/field/BlockReferenceField.php
    @@ -0,0 +1,110 @@
    + * Provides a field plugin for blockrefre fields.
    

    Typo: blockrefre.

  2. +++ b/src/Plugin/migrate/field/BlockReferenceField.php
    @@ -0,0 +1,110 @@
    +      'blockreference_default' => 'block_field',
    

    I would also map blockreference_without_title to block_field; and blockreference_title and blockreference_plain to block_field_label

  3. +++ b/src/Plugin/migrate/field/BlockReferenceField.php
    @@ -0,0 +1,110 @@
    +      'process' => [
    +        'source' => [
    +          'plugin' => 'explode',
    +          'source' => 'moddelta',
    +          'delimiter' => ':',
    +        ],
    +        'module' => [
    +          'plugin' => 'extract',
    +          'source' => '@source',
    +          'index' => [0],
    +        ],
    +        'delta' => [
    +          'plugin' => 'extract',
    +          'source' => '@source',
    +          'index' => [1],
    +        ],
    +        'plugin_id' => [
    +          [
    +            'plugin' => 'static_map',
    +            'bypass' => 'true',
    +            'source' => ['@module', '@delta'],
    +            'map' => [
    +              'book' => [
    +                'navigation' => 'book_navigation',
    +              ],
    +              'comment' => [
    +                'recent' => 'views_block:comments_recent-block_1',
    +              ],
    +              'forum' => [
    +                'active' => 'forum_active_block',
    +                'new' => 'forum_new_block',
    +              ],
    +              'node' => [
    +                'syndicate' => 'node_syndicate_block',
    +              ],
    +              'search' => [
    +                'form' => 'search_form_block',
    +              ],
    +              'statistics' => [
    +                'popular' => 'statistics_popular_block',
    +              ],
    +              'system' => [
    +                'main' => 'system_main_block',
    +                'powered-by' => 'system_powered_by_block',
    +              ],
    +              'user' => [
    +                'login' => 'user_login_block',
    +                'new' => 'views_block:who_s_new-block_1',
    +                'online' => 'views_block:who_s_online-who_s_online_block',
    +              ],
    +            ],
    +          ],
    +          [
    +            'plugin' => 'block_plugin_id',
    +          ],
    

    I thought a lot about how to always use the current process pipeline from core d7_block here - I have no better idea yet than doing this.

  4. +++ b/src/Plugin/migrate/field/BlockReferenceField.php
    @@ -0,0 +1,110 @@
    +            'plugin' => 'static_map',
    +            'bypass' => 'true',
    +            'source' => ['@module', '@delta'],
    

    bypass should be a boolean TRUE, not a string.

  5. +++ b/src/Plugin/migrate/field/BlockReferenceField.php
    @@ -0,0 +1,110 @@
    +
    +    $migration->mergeProcessOfProperty($field_name, $process);
    +  }
    

    Since block_plugin_id performs a lookup in the d7_custom_block migration, we should declare that the actual migration depends on d7_custom_block (it should be a required migration dependency).

    See \Drupal\migrate_drupal\Plugin\migrate\field\ReferenceBase::alterFieldInstanceMigration.

  6. +++ b/tests/src/Unit/Plugin/migrate/field/BlockReferenceFieldTest.php
    @@ -0,0 +1,119 @@
    +/**
    + * @coversDefaultClass \Drupal\block_field\Plugin\migrate\field\BlockReferenceField
    + * @group block
    + */
    

    Missing class doc comment and wrong test group annotation.

  7. +++ b/tests/src/Unit/Plugin/migrate/field/BlockReferenceFieldTest.php
    @@ -0,0 +1,119 @@
    +class BlockReferenceFieldTest extends UnitTestCase {
    

    This test does not add much value in its current state – basically it tests Drupal\views\Plugin\views\field\FieldPluginBase and Drupal\migrate\Plugin\Migration::mergeProcessOfProperty

huzooka’s picture

Title: Need a field migration plugin. » Add migration path for Blockreference → Block Field field values
Wim Leers’s picture

Status: Active » Needs work

Marking Needs work per #3, and especially for the missing migration dependency that @huzooka pointed out in point 5 of his review.

n4r3n’s picture

Thanks @huzooka and @wim for the inputs. Here I'm uploading updated patch and interdiff.

Status: Needs review » Needs work

The last submitted patch, 6: block_field-field_migration_plugin-3219319-6.patch, failed testing. View results

n4r3n’s picture

Status: Needs work » Needs review
FileSize
7.78 KB

Fixing failed test case.

huzooka’s picture

Status: Needs review » Needs work

@n4r3n, Sorry for the long wait.

  1. +++ b/src/Plugin/migrate/field/BlockReferenceField.php
    @@ -0,0 +1,126 @@
    +  public function alterFieldInstanceMigration(MigrationInterface $migration) {
    +    parent::alterFieldInstanceMigration($migration);
    +
    +    // Add the reference migration as a required dependency to this migration.
    +    $migration_dependencies = $migration->getMigrationDependencies();
    +    array_push($migration_dependencies['required'], 'd7_custom_block');
    +    $migration_dependencies['required'] = array_unique($migration_dependencies['required']);
    +    $migration->set('migration_dependencies', $migration_dependencies);
    +  }
    

    We only use the d7_custom_block migration when we try to migrate the actual field values, field instance migrations shouldn't depend on d7_custom_block.

    You have to add this dependency in the ::defineValueProcessPipeline() method.

  2. +++ b/tests/src/Unit/Plugin/migrate/field/BlockReferenceFieldTest.php
    @@ -0,0 +1,124 @@
    + * @group migrate
    

    This is still a wrong annotation (it should be block_field, because the current module's machine name is block_field).

    But now seriously, this test class isn't testing the plugin, it is testing the underlying (Migrate Drupal) infrastructure. It is completely redundant in its current state. Either rethink how to test actual value migrations, or remove it.

p.s: Next time please generate an interdiff about the changes since the last review (or if you like it better, about each change).

n4r3n’s picture

thank you for the review @huzooka. Here I'm uploading updated patch with interdiff.

n4r3n’s picture

Status: Needs work » Needs review
huzooka’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/src/Plugin/migrate/field/BlockReferenceField.php
@@ -0,0 +1,118 @@
+    // Add the d7_custom_block migration as a required dependency to this migration.

Comment line is longer than 80 characters. (Should be fixed before/on commit.)

n4r3n’s picture