Comments

omkar.podey created an issue. See original summary.

omkar.podey’s picture

StatusFileSize
new55.54 KB

Initial patch.

omkar.podey’s picture

StatusFileSize
new54.98 KB

Updated tests.

omkar.podey’s picture

Status: Active » Needs review
narendrar’s picture

Status: Needs review » Needs work

Tested manually and added my observations below:

  1. +++ b/maxlength.module
    @@ -176,3 +179,65 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +    function ($definition) {
    +      return $definition['id'] === 'd7_field_instance_widget_settings';
    +    }
    +  );
    +
    +  foreach (array_keys($field_instance_widget_settings_migrations) as $plugin_id) {
    

    Check if Maxlength module is enabled on the source site or not.

  2. +++ b/maxlength.module
    @@ -176,3 +179,65 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +  $unserialised_data = unserialize($row->getSourceProperty('data'));
    

    What if $row->getSourceProperty('data') does not have any value?

  3. +++ b/maxlength.module
    @@ -176,3 +179,65 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +  if (array_key_exists("maxlength_js", $unserialised_data)) {
    +
    +    switch ($row->getSourceProperty('field_definition')['type']) {
    

    Extra space

  4. +++ b/maxlength.module
    @@ -176,3 +179,65 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +      case 'text':
    +        $maxlength_config['maxlength_js'] = unserialize($row->getSourceProperty('field_definition')['data'])['settings']['max_length'];
    +        $maxlength_config['maxlength_js_label'] = $unserialised_data['maxlength_js_label'];
    +        break;
    +
    +      case 'text_long':
    

    Title and link migration missing.
    To reproduce link migration issue enable https://www.drupal.org/project/link

  5. +++ b/maxlength.module
    @@ -176,3 +179,65 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +        $maxlength_config['maxlength_js_label'] = $unserialised_data['maxlength_js_label'];
    

    Common data can be moved above switch case.

  6. +++ b/maxlength.module
    @@ -176,3 +179,65 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +
    

    Remove extra space wherever possible.

  7. +++ b/tests/fixtures/drupal7.php
    @@ -0,0 +1,22 @@
    +include 'drupal7' . DIRECTORY_SEPARATOR . 'node.php';
    +include 'drupal7' . DIRECTORY_SEPARATOR . 'node_comment_statistics.php';
    

    Seems irrelevant to me.

  8. +++ b/tests/src/Kernel/MaxlengthMigrationTest.php
    @@ -0,0 +1,151 @@
    +  protected static $configSchemaCheckerExclusions = [
    +    'core.entity_form_display.comment.comment_node_article.default',
    +    'core.entity_form_display.node.article.default',
    +    'core.entity_form_display.node.page.default',
    +    'core.entity_form_display.node.webform.default',
    +    'core.entity_form_display.user.user.default',
    +    'core.entity_form_display.taxonomy_term.some_tax.default',
    +  ];
    

    Do we require this in this case?

  9. +++ b/tests/src/Kernel/MaxlengthMigrationTest.php
    @@ -0,0 +1,151 @@
    +  protected function setUp() {
    +    // @todo Change the autogenerated stub
    +    parent::setUp();
    +    $this->installConfig(['node']);
    +    $this->installEntitySchema('node');
    +    $this->installConfig(['comment']);
    +    $this->installEntitySchema('comment');
    +  }
    

    Is it required in this case?

omkar.podey’s picture

StatusFileSize
new18.84 KB
new53.17 KB

Updated as per review.

omkar.podey’s picture

Status: Needs work » Needs review
narendrar’s picture

Status: Needs review » Needs work
  1. +++ b/maxlength.module
    @@ -176,3 +181,91 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +  $unserialised_data = $row->getSourceProperty('widget')['settings'];
    +  $maxlength_config = [];
    +  if ($row->getSourceProperty('field_definition')['type'] === 'link_field') {
    

    Title field maxlength configurations are still not migrated.

  2. +++ b/maxlength.module
    @@ -176,3 +181,91 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +        $maxlength_config['maxlength_js_label'] = $unserialised_data['maxlength_js_label'];
    

    This line can be added outside switch case.

  3. +++ b/tests/fixtures/drupal7.php
    @@ -0,0 +1,20 @@
    +include 'drupal7' . DIRECTORY_SEPARATOR . 'comment.php';
    

    This is not required.

omkar.podey’s picture

StatusFileSize
new16.52 KB
new56.75 KB

Updated as per review.

omkar.podey’s picture

Updated with custom deriver.

omkar.podey’s picture

Status: Needs work » Needs review
huzooka’s picture

Re #11: Very nice job, I've only a few minor nits.

  1. +++ b/maxlength.module
    @@ -176,3 +181,89 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +/**
    + * Implements hook_migrate_prepare_row().
    + *
    + * Alters maxlength config before being pushed into
    + * d7_field_instance_widget_settings.
    + */
    +function maxlength_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
    +  if ($migration->getBaseId() !== 'd7_field_instance_widget_settings' || !in_array('maxlength', $migration->getMigrationTags())) {
    +    return;
    +  }
    

    It is enough to check whether the maxlength migration tag is present or not.

  2. +++ b/maxlength.module
    @@ -176,3 +181,89 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +  $unserialised_data = $row->getSourceProperty('widget')['settings'];
    

    This reads better if you write $row->getSourceProperty('widget/settings').
    In addition, the name of the variable should refer to the data in it, e.g. $widget_settings

  3. +++ b/maxlength.module
    @@ -176,3 +181,89 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +  if ($row->getSourceProperty('field_definition')['type'] === 'link_field') {
    ...
    +    switch ($row->getSourceProperty('field_definition')['type']) {
    

    The data in field_definition/type is the same what is already available in the type source property (it is the field type).

  4. +++ b/maxlength.module
    @@ -176,3 +181,89 @@ function maxlength_field_widget_form_alter(&$element, FormStateInterface $form_s
    +  if (array_key_exists("maxlength_js", $unserialised_data)) {
    ...
    +  else {
    +    $row->setSourceProperty('maxlength_config', NULL);
    +  }
    

    We don't have to do anything if the array key does not exist (I mean you don't need the else statement at all). And other than that, if $unserialized_data['maxlength_js'] is 0, then there is no limitation, so we shouldn't migrate any maxlength configuration.

    With these in mind, I would say just use an early return:

    if (empty($var['maxlength_js']) {
      return;
    }
    
  5. +++ b/migrations/d7_maxlength_title_settings.yml
    @@ -0,0 +1,24 @@
    +migration_dependencies:
    +  required:
    +    - d7_node_type
    

    It would be nice to provide an optional support for the core patch at #3097336: Improve the DX for migrating content entities: view modes, fields, formatters, widgets etc should be migrated per entity type + bundle.

  6. +++ b/src/Plugin/migrate/source/Maxlength.php
    @@ -0,0 +1,63 @@
    +    if (!empty($this->configuration["node_type"])) {
    +      $query->condition('name', 'maxlength_js_label_' . $this->configuration["node_type"]);
    

    Please prefer single quotes where possible!
    https://www.drupal.org/docs/develop/standards/coding-standards#quotes

  7. +++ b/tests/src/Kernel/MaxlengthMigrationTest.php
    @@ -0,0 +1,161 @@
    +/**
    + * Tests D7 maxlength migration plugin.
    + *
    + * @group maxlength
    + */
    +class MaxlengthMigrationTest extends MigrateDrupal7TestBase {
    +  /**
    

    An empty line is missing at the beginning of this test class' body (after the opening curly brace).

omkar.podey’s picture

Updated as per review.

omkar.podey’s picture

Updated with Dynamic migration dependencies.

huzooka’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/migrate/MaxlengthDeriver.php
@@ -0,0 +1,48 @@
+        $derivative_definition['migration_dependencies']['required'] = ['d7_node_type:' . $node_type];

The d7_node_type migration isn't a derived migration in Drupal core; the thing what makes it available is the patch at #3097336: Improve the DX for migrating content entities: view modes, fields, formatters, widgets etc should be migrated per entity type + bundle.

By default, the node label max length migrations should depend on d7_node_type. But if the patch in 3097336 is applied, then these migration should (and can) depend on the corresponding d7_node_type derivative.

Edit: I was wrong. You can ignore my concern at #12.5.

omkar.podey’s picture

Updated as per review.

omkar.podey’s picture

Status: Needs work » Needs review
huzooka’s picture

Assigned: omkar.podey » Unassigned
Status: Needs review » Reviewed & tested by the community

#16 deserves RTBC.

Thank you, @omkar.podey, great work!

wim leers’s picture

After may months in use, not a single problem reported.

hipp2bsquare’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for the good work, omkar, for the review and feedback, huzooka, and for the prodding, Wim! Committing this to the project.

hipp2bsquare’s picture

Status: Fixed » Needs work

Alas, I spoke to soon -- I just caught that there is a coding standards issue w/ line 263:

      $maxlength_config['maxlength_js'] = unserialize($row->getSourceProperty('field_definition')['data'])['settings']['max_length']
unserialize() is insecure unless allowed classes are limited. Use a safe format like JSON or use the allowed_classes option.
(DrupalPractice.FunctionCalls.InsecureUnserialize.InsecureUnserialize)
adaucyj’s picture

Assigned: Unassigned » adaucyj

I'll work on it.

adaucyj’s picture

Assigned: adaucyj » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.97 KB
new53.37 KB

Could someone review it, please.

Arturo-q’s picture

Assigned: Unassigned » Arturo-q

Hi, I will review it.

Arturo-q’s picture

Assigned: Arturo-q » Unassigned
Status: Needs review » Reviewed & tested by the community

Thanks, @Adaucyj, for the patch, it fixes the last CS issue.
Moving to RTBC.

cedewey’s picture

Issue tags: +code review
cedewey’s picture

Version: 2.0.x-dev » 2.1.x-dev
Status: Reviewed & tested by the community » Needs review

Marking as needs review to check if anything needs updating to make it work with the 2.1.x branch.