Problem/Motivation

Right now, the migrated field group settings are changed when the corresponding entity (form/view) display configuration entity is re-saved on Field UI.

Proposed resolution

Migrate well-prepared field group settings that do not change when the entity (form/view) display is re-saved.

Remaining tasks

* Create a patch
* Add a functional test which ensures that field group settings do not change.
* Update the test fixture with proper test data (e.g. a tab should have a *tabs parent etc.)

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Assigned: huzooka » Unassigned
Status: Active » Needs review
FileSize
29.74 KB
huzooka’s picture

Title: Field group should migrate settings that do not change when the entity (form/view) display is re-saved » Field Group should migrate settings that do not change when the entity (form/view) display is re-saved
Wim Leers’s picture

  1. +++ b/contrib/field_group_migrate/src/Plugin/migrate/source/d7/FieldGroup.php
    @@ -68,8 +120,20 @@ class FieldGroup extends DrupalSqlBase {
    +    // Add default settings.
    +    $context = $row->getSourceProperty('mode') === 'form' ? 'form' : 'view';
    +    $default_settings = $this->fieldGroupFormatterManager->prepareConfiguration($settings['format_type'], $context, $settings);
    +    $settings['format_settings'] += $default_settings['settings'];
    

    🤔 Is this what causes the field group configuration that gets added to the Entity(View|Form)Display to be restructured/reformatted to ensure that subsequent saves via the UI do not cause things to change anymore?

    IOW, is this what you meant by

    Migrate well-prepared field group settings […]

    ?

  2. +++ b/contrib/field_group_migrate/src/Plugin/migrate/source/d7/FieldGroup.php
    @@ -68,8 +120,20 @@ class FieldGroup extends DrupalSqlBase {
    +    // Clean up obsolete settings.
    +    switch ($settings['format_type']) {
    +      case 'tabs':
    +        unset($settings['format_settings']['formatter']);
    +        break;
         }
    

    🤔 Why are these obsolete? An @see would be helpful here!

  3. +++ b/contrib/field_group_migrate/tests/src/Functional/MigrateUiFieldGroupTest.php
    @@ -0,0 +1,201 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    

    {@inheritdoc}

    🤓

  4. +++ b/contrib/field_group_migrate/tests/src/Functional/MigrateUiFieldGroupTest.php
    @@ -0,0 +1,201 @@
    +    $this->assertNodeArticleDefaultForm();
    +    $this->assertNodePageDefaultForm();
    +    $this->assertNodeArticleTeaserDisplay();
    +    $this->assertNodePageDefaultDisplay();
    +    $this->assertUserDefaultDisplay();
    +
    +    // Re-save every field group's configuration to ensure that the migrated
    +    // settings aren't changed.
    +    $this->drupalGet(Url::fromRoute('entity.entity_form_display.node.default', [
    +      'node_type' => 'article',
    +    ]));
    +    $page->findButton('group_article_htabs_group_settings_edit')->click();
    +    $page->findButton('Update')->click();
    +    $page->findButton('group_article_group_settings_edit')->click();
    +    $this->submitForm([], 'Save');
    +
    +    $this->drupalGet(Url::fromRoute('entity.entity_form_display.node.default', [
    +      'node_type' => 'page',
    +    ]));
    +    $page->findButton('group_page_group_settings_edit')->click();
    +    $page->findButton('Update')->click();
    +    $page->findButton('group_page_tab_group_settings_edit')->click();
    +    $this->submitForm([], 'Save');
    +
    +    $this->drupalGet(Url::fromRoute('entity.entity_view_display.node.view_mode', [
    +      'node_type' => 'article',
    +      'view_mode_name' => 'teaser',
    +    ]));
    +    $page->findButton('group_article_htabs_group_settings_edit')->click();
    +    $page->findButton('Update')->click();
    +    $page->findButton('group_article_group_settings_edit')->click();
    +    $this->submitForm([], 'Save');
    +
    +    $this->drupalGet(Url::fromRoute('entity.entity_view_display.node.default', [
    +      'node_type' => 'page',
    +    ]));
    +    $page->findButton('group_page_group_settings_edit')->click();
    +    $this->submitForm([], 'Save');
    +
    +    $this->drupalGet(Url::fromRoute('entity.entity_view_display.user.default'));
    +    $page->findButton('group_user_group_settings_edit')->click();
    +    $page->findButton('Update')->click();
    +    $page->findButton('group_user_child_group_settings_edit')->click();
    +    $page->findButton('Update')->click();
    +    $page->findButton('group_user_tab1_group_settings_edit')->click();
    +    $page->findButton('Update')->click();
    +    $page->findButton('group_user_tab2_group_settings_edit')->click();
    +    $this->submitForm([], 'Save');
    +
    +    // Re-test the migrated field group configurations.
    +    $this->assertNodeArticleDefaultForm();
    +    $this->assertNodePageDefaultForm();
    +    $this->assertNodeArticleTeaserDisplay();
    +    $this->assertNodePageDefaultDisplay();
    +    $this->assertUserDefaultDisplay();
    

    👍 Aha, so this first checks the configuration of multiple view displays and form displays post-migration, then navigates to the admin UI for each, resaves it through the UI, and verifies they do not get overwritten.

huzooka’s picture

Assigned: Unassigned » huzooka
Status: Needs review » Needs work
huzooka’s picture

Title: Field Group should migrate settings that do not change when the entity (form/view) display is re-saved » Migrate well-prepared field group settings that do not change when the entity (form/view) displays are re-saved
Assigned: huzooka » Unassigned
Status: Needs work » Needs review
FileSize
29.85 KB
1.33 KB

Re #4:

  1. Yes, thanks! Issue title changed.
  2. Added a comment. (Ideally, these kind of transformations should be handled in a process plugin.)
  3. Fixed.
  4. Exactly!
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

🚢

nils.destoop’s picture

Everything seems to be ok. I had to re-apply the patch, just a quick check if tests are still ok:

Neslee Canil Pinto’s picture

Status: Reviewed & tested by the community » Needs work

@nils.destoop the tests are failing at #8 , setting to NW.

huzooka’s picture

huzooka’s picture

BTW, why this width_breakpoint setting is not in the default configuration? (Or why it is not nullable?..)

omkar.podey’s picture

omkar.podey’s picture

Updated and making some values default to pass assertions.

omkar.podey’s picture

omkar.podey’s picture

Status: Needs work » Needs review
huzooka’s picture

Status: Needs review » Needs work

I have only two nits, #1 and #2:

  1. +++ b/src/Plugin/field_group/FieldGroupFormatter/HtmlElement.php
    @@ -57,7 +57,8 @@ class HtmlElement extends FieldGroupFormatterBase {
    +      // If user also entered class in the ¶
    +      // attributes textfield, force it to an array.
    

    Unneeded trailing whitespace. Although I would not touch this comment (because it is not related to the task),
    if you want to do it anyway, let's break it before 'array.'.

  2. +++ b/src/Plugin/field_group/FieldGroupFormatter/Tabs.php
    @@ -77,8 +77,10 @@ class Tabs extends FieldGroupFormatterBase {
    -    // Make sure the group has 1 child. This is needed to succeed at form_pre_render_vertical_tabs().
    -    // Skipping this would force us to move all child groups to this array, making it an un-nestable.
    +    // Make sure the group has 1 child. This is needed ¶
    +    // to succeed at form_pre_render_vertical_tabs().
    +    // Skipping this would force us to move all child groups ¶
    +    // to this array, making it an un-nestable.
    

    See point #1 above. The char limit is 80.

  3. +++ b/src/Plugin/field_group/FieldGroupFormatter/Tab.php
    +++ b/src/Plugin/field_group/FieldGroupFormatter/Tab.php
    @@ -115,6 +115,7 @@ class Tab extends FieldGroupFormatterBase {
    
    @@ -115,6 +115,7 @@ class Tab extends FieldGroupFormatterBase {
         $defaults = [
           'formatter' => 'closed',
           'description' => '',
    +      'show_empty_fields' => FALSE,
         ] + parent::defaultSettings($context);
     
    
    +++ b/src/Plugin/field_group/FieldGroupFormatter/Tabs.php
    @@ -77,8 +77,10 @@ class Tabs extends FieldGroupFormatterBase {
    @@ -134,6 +136,7 @@ class Tabs extends FieldGroupFormatterBase {
    
    @@ -134,6 +136,7 @@ class Tabs extends FieldGroupFormatterBase {
         return [
           'direction' => 'vertical',
           'width_breakpoint' => 640,
    +      'show_empty_fields' => FALSE,
         ] + parent::defaultContextSettings($context);
       }
    

    👍 These are the only major differences - the default value of show_empty_fields wasn't added to the default context settings of Tab and Tabs in #1482958: Allow field_group with empty fields to be displayed via setting (4 month ago).

omkar.podey’s picture

omkar.podey’s picture

Status: Needs work » Needs review
omkar.podey’s picture

omkar.podey’s picture

huzooka’s picture

Status: Needs review » Reviewed & tested by the community

#20 is RTBC.

nils.destoop’s picture

Status: Reviewed & tested by the community » Fixed

Thx, this has been committed to dev

Status: Fixed » Closed (fixed)

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