Sub-issue for meta issue #1880976: [meta] Port examples (including submodules) to D9.4+

Problem/Motivation

D8 all the things!

Proposed resolution

Start with D7 version and figure out how to port ;)

Testing Instructions

  1. Enable Bartik or other theme (except seven theme) as administration theme.
  2. Enable the module.
  3. Try adding new article or basic page
  4. You should be able to see a new vertical tab with a checkbox.
  5. Tick the checkbox and try to update the default summary.

The summary should update!!

Issue fork examples-2102695

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

juanjesustrigo’s picture

Assigned: Unassigned » juanjesustrigo
Issue summary: View changes

I'll work on this

Mile23’s picture

Great, thanks!

Be sure and check out the examples module checklist: #2209627: [meta] Module Checklist for Examples

marvil07’s picture

Assigned: juanjesustrigo » Unassigned

Unassigning for now, please add a patch if there is some initial work done.

Palashvijay4O’s picture

Assigned: Unassigned » Palashvijay4O

Will be working on the issue .

Palashvijay4O’s picture

Status: Active » Needs review
FileSize
2.87 KB

Here's the first patch. I was having a problem in linking the node/add page to content using \Drupal::l() . Please check if i am doing something wrong so that I can go ahead .
Thanks!

Palashvijay4O’s picture

FileSize
2.71 KB

Sorry for the wrong patch.

Palashvijay4O’s picture

Thanks Mile23 it worked for me after changing node/add to node/add_page .
Will be working on this ahead.

Status: Needs review » Needs work

The last submitted patch, 6: 2102695-6.patch, failed testing.

The last submitted patch, 5: 2102695-5.patch, failed testing.

Kristen Pol’s picture

Palashvijay4O - Thanks for working on this issue. I haven't ported a module from D7 => D8 so someone else will need to review your work. I can help with testing though once you think you are done with the code.

Palashvijay4O’s picture

Status: Needs work » Needs review

I have ported whole module but only part that is not working is the summary that needs to be updated when checkbox is checked is not showing . Please someone help me over this.
The link to the sandbox port of this module is https://www.drupal.org/sandbox/palashvijay4/2428101
Thanks !!

Palashvijay4O’s picture

There is some problem in js file help me over this I am not sure exactly what is wrong but what I think is the change in css of the node/edit page of drupal 8 as compared to drupal 7 .

mrjmd’s picture

@Palashvijay4O, I've fixed up and submitted a patch over on your sandbox. See #2434151: JS fixes and switch to details field. I'll attach the patch here as well but it applies against the sandbox.

Status: Needs review » Needs work

The last submitted patch, 13: vertical_tabs_example-2434151-1.patch, failed testing.

mrjmd’s picture

Status: Needs work » Needs review
FileSize
103.2 KB
117.77 KB

Switching back to needs review, that fail is expected since patch applies elsewhere. Here are a couple of screenshots. I should have mentioned, I had to switch the admin theme to see this properly, because the Seven theme overrides how vertical tabs work. That is probably an issue that needs further discussion.

Palashvijay4O’s picture

I think https://www.drupal.org/sandbox/palashvijay4/2428101 is ready to be commited.

mrjmd’s picture

Assigned: Palashvijay4O » Unassigned
FileSize
7.81 KB

Patch attached against current 8.x-1.x branch.

Kristen Pol’s picture

Status: Needs review » Needs work

I see the EXAMPLE VERTICAL TAB in the node edit form… I'm not sure what the "Use this setting instead" is supposed to do though… I haven't tried the D7 version… when I type text into "Use this setting instead" I don't see anything obviously change.

Please add test instructions to the issue summary. Thanks!

Kristen Pol’s picture

Palashvijay4O said to try with Bartik as admin theme and I did that. When I click the checkbox and change the "Use this setting instead" text, I do see the description change for the tab. But, when I save the form and go back, the checkbox is unchecked and the text I added before is wiped out. Is this intentional?

Palashvijay4O’s picture

The same thing happens with D7 version of this module so I guess pretty much that is intentional. And also I think the lesson is about adding vertical tabs to the node edit/add form.

Palashvijay4O’s picture

Issue summary: View changes
Issue tags: +Review changes updated...
Kristen Pol’s picture

For a proper review, someone with more D8 experience needs to take a look. I found a couple minor commenting things:

+++ b/vertical_tabs_example/js/vertical_tabs_example.js
@@ -0,0 +1,23 @@
+      // Use the details class to identify the vertical tab element

Nitpick: Use periods in comments.

+++ b/vertical_tabs_example/vertical_tabs_example.module
@@ -0,0 +1,68 @@
+
+/**
+ * @param array $form
+ * @param \Drupal\Core\Form\FormStateInterface $form_state

Should there be a comment?

Palashvijay4O’s picture

Status: Needs work » Needs review
FileSize
7.73 KB

Made changes as suggested. Please review.

Status: Needs review » Needs work

The last submitted patch, 23: 2102695-23.patch, failed testing.

Palashvijay4O’s picture

Status: Needs work » Needs review
FileSize
7.73 KB

Sorry submitted a wrong patch.

Kristen Pol’s picture

Status: Needs review » Reviewed & tested by the community

This is working for me on simplytest.me and I see the comments were updated. I'll mark this RTBC but someone with experience writing D8 modules should really take a look.

Mile23’s picture

Status: Reviewed & tested by the community » Needs work

First, really sorry about not getting to this sooner.

Second, thanks for sticking with it.

And third, here are a few things:

  1. +++ b/vertical_tabs_example/src/Controller/VerticalTabsExampleController.php
    @@ -0,0 +1,34 @@
    +      '#markup' => t('The Vertical Tabs Example shows how a
    +        custom module can add a vertical tab to a node edit form,
    +        and support its summary field with JavaScript. To see the
    +        effects of this module, !content_add and look at the set
    +        of tabs at the bottom. We\'ve added one called \'Example vertical tab.\'',
    +        array('!content_add' => $content_add)
    

    This is incorrect because the settings tabs are beside the content now, instead of below.

  2. +++ b/vertical_tabs_example/src/Tests/VerticalTabsExampleTest.php
    @@ -0,0 +1,41 @@
    +  public function testVerticalTabsExampleMenus() {
    

    This test should also look for the menu links from the front page.

    We also need tests for:

    • Whether the tab appears on the node/add page.
    • Whether our new setting gets saved properly.
  3. +++ b/vertical_tabs_example/vertical_tabs_example.info.yml
    --- /dev/null
    +++ b/vertical_tabs_example/vertical_tabs_example.libraries.yml
    

    This file should have # comments telling you why you're including these libraries.

  4. +++ b/vertical_tabs_example/vertical_tabs_example.module
    --- /dev/null
    +++ b/vertical_tabs_example/vertical_tabs_example.routing.yml
    

    We have routing.yml but not links.menu.yml, so the link never appears on the front page.

Mile23’s picture

As we discussed in IRC there is an issue with the status update JS. Let's be sure and address that after the other items above.

tim.plunkett’s picture

Issue tags: -Review changes updated...

Not a real issue tag.

navneet0693’s picture

@Mile23

Are we saving the settings ? I have gone through the code, i couldn't see it. Please correct me if I am wrong. Only JS part is not working with "Seven" theme. Works good with Bartik and others.

navneet0693’s picture

Status: Needs work » Needs review
FileSize
3.76 KB
8.89 KB

@Mile23 Completed tasks mentioned in #27. The summary in "Seven" as Administrator theme, is not supported I guess. Please, correct me, if I am wrong.

Status: Needs review » Needs work

The last submitted patch, 31: port-vertical_tab_example-2102695-31.patch, failed testing.

navneet0693’s picture

Added some more test and corrected placeholder.

Manuel Garcia’s picture

Status: Needs review » Needs work
+++ b/vertical_tabs_example/vertical_tabs_example.module
@@ -0,0 +1,66 @@
+    '#collapsible' => TRUE,

#collapsible doesn't exist for details.

#collapsed is now #open

Manuel Garcia’s picture

The form here needs a lot of work.
While working on #1148950: Applying #states to a vertical tab does not update the vertical tabs menu I created a test module for the issue, feel free to have a look to see how to setup a form with vertical tabs on Drupal 8. Just enable it and go to /vertical_tabs_states_test/form/default.

navneet0693’s picture

Thanks @Manuel Garcia, I will work on this further more after look into your code.

navneet0693’s picture

Assigned: Unassigned » navneet0693

Starting working on this again!

navneet0693’s picture

Re-rolled it. But as said, this will only work with themes other than "Seven" as administration theme.

navneet0693’s picture

Assigned: navneet0693 » Unassigned
Status: Needs work » Needs review
Mile23’s picture

Status: Needs review » Needs work
FileSize
9.35 KB
5.51 KB

I improved the inline comments some, fixed CS errors, made it explicitly require node module.

Still needs:

  • Convert the test to BrowserTestBase.
  • Ideally, add a JavaScript test to verify that the summary is added to the form, but that can be a follow-up.
Mile23’s picture

Status: Needs work » Needs review
navneet0693’s picture

Converted test to BTB.

Manuel Garcia’s picture

Status: Needs review » Needs work

Thanks @navneet0693!

+++ b/vertical_tabs_example/tests/src/Functional/VerticalTabsExampleTest.php
@@ -0,0 +1,52 @@
+    $this->assertNotNull($this->xpath("//details[@id='edit-vertical-tabs-example']"));

Let's use $web_assert->elementExists('css', '#edit-vertical-tabs-example'); instead.

navneet0693’s picture

Status: Needs work » Needs review
FileSize
816 bytes
9.4 KB

@Manuel Garcia,

Done :-)

Manuel Garcia’s picture

Status: Needs review » Needs work

Thanks for that @navneet0693 :)

#34 still needs to be addressed. Also see #35

navneet0693’s picture

@Manuel Garcia,

Thank you, I will work upon it :-)

Mile23’s picture

valthebald made their first commit to this issue’s fork.