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

Problem/Motivation

D8 all the things!

Ajax Add more example is already added in fapi_example module : #2720361: Port ajax example add more and remove example from drupal 7 to drupal 8

Proposed resolution

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

CommentFileSizeAuthor
#50 interdiff.txt34.59 KBMile23
#50 2102639_50.patch57.88 KBMile23
#49 interdiff.txt14.12 KBMile23
#49 2102639_49.patch62.62 KBMile23
#48 interdiff.txt5.75 KBMile23
#48 2102639_48.patch60.87 KBMile23
#47 interdiff.txt91.36 KBMile23
#46 interdiff.txt91.36 KBMile23
#46 2102639_46.patch56.51 KBMile23
#44 interdiff.txt44.78 KBMile23
#42 2102639_42.patch107.36 KBMile23
#39 interdiff.txt6.16 KBpiyuesh23
#39 ajaxexample-2102639-39.patch103.56 KBpiyuesh23
#38 interdiff.txt24.65 KBLal_
#38 ajaxexample-2102639-38.patch100.93 KBLal_
#37 ajaxexample-2102639-37.patch107.56 KBLal_
#33 interdiff.txt65.26 KBLal_
#33 ajaxexample-2102639-33.patch107.56 KBLal_
#30 ajaxexample-2102639-30.patch96.24 KBLal_
#29 ajaxexample-2102639-29.patch93.07 KBLal_
#26 ajaxexample-2102639-26.patch54.77 KBLal_
interdiff.txt53.11 KBLal_
ajaxexample-2102639-24.patch57.2 KBLal_
#20 ajaaxexample-2102639-20.patch34.43 KBLal_
#19 interdiff.txt5.67 KBLal_
#19 ajaxexample-2102639-19.patch10.27 KBLal_
#15 port_ajax_example-2102639-15.patch6.61 KBnavneet0693
#13 2102639-13.examples.ajax_.patch6.9 KBjoachim
#2 examples-ajax_example_d8_port-2.patch6.06 KBkerasai
#1 examples-ajax_example_d8_port-1.patch6.08 KBkerasai
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kerasai’s picture

Issue summary: View changes
Status: Active » Needs work
FileSize
6.08 KB

Started work on a port. Attached patch provides the framework of the module, and the first (of many) examples.

I'll try to attack the rest as time allows, others feel free to jump in.

kerasai’s picture

FileSize
6.06 KB

Whoopsie, made patch backwards. New patch attached.

Mile23’s picture

Status: Needs work » Needs review
kalinchernev’s picture

Putting this one on my list for a review during this week

kalinchernev’s picture

Assigned: Unassigned » kalinchernev
kerasai’s picture

There is most certainly work to be done on this one. I believe @Mile23 set it to "needs review" to fire off the testbot.

Mile23’s picture

No, I set it to 'needs review' because it needs a review. :-) Part of that is the testbot.

If you'd like to make a list of things that need to be done, that would be great, and would count as a review.

kalinchernev’s picture

Hi, thanks for quick reply.
My plan is to check the example provided by kerasai as methods, etc.
I want to spend more time into that in order to see the rest of the examples as well and help with what I can for the rest as well, so basically this is why I assigned the ticket to spend more time and go into details.

kalinchernev’s picture

Hi back, the patch is ok and works well. It's indeed a good base example of the simplest case.

I would only change the usage of t() function at the current state, the rest is a good start!

  1. +++ b/ajax_example/src/Form/AjaxExampleSimplest.php
    @@ -0,0 +1,78 @@
    +      '#title' => t("Choose something and explain why"),
    

    it's better to use the $this->t(), because global functions will be gone at some point and the FormBase takes the StringTranslationTrait which provides the method

  2. +++ b/ajax_example/src/Form/AjaxExampleSimplest.php
    @@ -0,0 +1,78 @@
    +      '#title' => t("Why"),
    

    the other t()

  3. +++ b/ajax_example/src/Form/AjaxExampleSimplest.php
    @@ -0,0 +1,78 @@
    +      $form['replace_textfield']['#description'] = t("Say why you chose '@value'", array('@value' => $value));
    

    t()

kalinchernev’s picture

Assigned: kalinchernev » Unassigned
kalinchernev’s picture

On another note, there are 23 more hook_menu items which can also be converted, and I could take on some.
@Mile23, do you think it will be better to continue with patches on same path 1:1 scenarios, or we can re-group scenarios into longer form with more examples? The question basically is if any reorganization is planned anyway

Mile23’s picture

Status: Needs review » Needs work

OK, so a review of the patch includes:

I can't see the link in the tool menu when I enable the module.

Aside from that, to address #11: The idea is to do a straight port as much as is feasible. We want each example to be as simple to read as possible; putting a lot of them together in a controller might confuse the issue. Remember the point here is to instruct people on how to do these things in a clear way.

joachim’s picture

I'm a bit confused by this patch, as it doesn't seem to be a straight port of the D7 module.

- The 'Choose something and explain why' form doesn't seem to exist on D7
- The D7 module contains several other AJAX forms.

Not sure what should be done here.

Anyway, in the meantime, here's an update of patch #2 with these issues fixed:

> It's better to use the $this->t(), because global functions will be gone at some point

> I can't see the link in the tool menu when I enable the module.

navneet0693’s picture

Agreed to @joachim,

If we look here : http://cgit.drupalcode.org/examples/tree/ajax_example/ajax_example.modul...
There are several ajax examples previously in D7 version of Ajax Example.

@Mile23, What do you think, if want simplest version. I can go ahead and test patch given in #13.

navneet0693’s picture

Hi @Mile23,

I somehow faced an issue of
Symfony\Component\Routing\Exception\RouteNotFoundException: Route "ajax_example" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 193 of /core/lib/Drupal/Core/Routing/Route with patch submitted in #13.

So, I have created a new patch which also replaces underscores with hyphens in path. Also, added $this->t() as suggest in #9.

Manav’s picture

Status: Needs review » Reviewed & tested by the community

This patch works fine for me.

Mile23’s picture

Status: Reviewed & tested by the community » Needs work

OK, so we have here a small piece of a port. It does demonstrate some use of AJAX, but doesn't port the rest of the example.

Assuming we're OK with only porting a little piece of it, here's a review. Consult #2209627: [meta] Module Checklist for Examples for some more stuff to consider.

We don't have a link in the tools menu for the AJAX page.

We don't have an assertion that there's a link in the tools menu.

We don't have any tests of the behavior of the page, such as to demonstrate that the page form even displays.

We now have javascript functional tests, which we could use on this example: https://api.drupal.org/api/drupal/core%21tests%21Drupal%21FunctionalJava... However, just a straight port of the D7 ajax_example tests would be good enough for now.

As far as how we split all this up into controller classes, I think just one controller with many methods would be fine for a documentation project such as this. If they could be chunked out into related types, that'd be great, but it's not essential.

pfrenssen’s picture

+++ b/ajax_example/ajax_example.module
@@ -0,0 +1,23 @@
+ * @file
+ * AJAX Examples module file with basic examples.

+++ b/ajax_example/src/Form/AjaxExampleSimplest.php
@@ -0,0 +1,78 @@
+      // The prefix/suffix provide the div that we're replacing, named by
+      // #ajax['wrapper'] above.
+      '#prefix' => '<div id="replace_textfield_div">',
+      '#suffix' => '</div>',

This is not good practice, it's better to wrap the textfield in a container than directly injecting HTML like this.

See AjaxFormsTestSimpleForm for an example.

I would also not call this element 'replace_textfield_div', but instead give it a semantically correct name.

Lal_’s picture

Assigned: Unassigned » Lal_
FileSize
10.27 KB
5.67 KB

This is the progress bar Ajax example. Well the example is not completely working, I am having some Ajax errors...

Lal_’s picture

This is patch consist of Generate check boxes example, Generate text field, Submit-driven AJAX, Dependent dropdown, Dependent dropdown (with graceful degradation), Dependent dropdown with javascript off. But I am still stuck with

Progress bar example which I've mentioned in the comment #19

Submit function is not working for the Dependent dropdown (with graceful degradation), Dependent dropdown with javascript off.

Mile23’s picture

Status: Needs work » Needs review
Lal_’s picture

I am still working for a perfect patch... https://github.com/abhilal007/AJAX-example , you can find it here

navneet0693’s picture

Issue summary: View changes
Lal_’s picture

I was able complete few examples... but I am currently facing issues with the wizard and progress bar examples which is not working on the above patch...

Status: Needs review » Needs work

The last submitted patch, ajaxexample-2102639-24.patch, failed testing. View results

Lal_’s picture

Lal_’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 26: ajaxexample-2102639-26.patch, failed testing. View results

Lal_’s picture

This patch consist of AJAX advanced example.. but I am having some problems at two parts (forms) of the
1) ajax_example_advanced_commands_css_callback (the box is not created at the styles)
2) ajax_example_advanced_commands_restripe_num_rows , this function is also not working...
remaining function seems to be work properly...
also the progress bar example is not working properly and the Wizard is working partially

Lal_’s picture

I was able to port the most of the example :-
1) AJAX framework commands
2) Add more button (with graceful degradation) w/JS turned off
3) Ajax Add more button
4) Ajax Wizard Example
5) Ajax Wizard Example w/JS turned off
6) Contextual Links Example
7) Dependent dropdown
8) Dependent dropdown degardes
9) Dependent dropdown degardes w/JS turned off
10) Dynamic Sections (with graceful degradation)
11) Dynamic Sections (with graceful degradation) w/js turned off
12) Generate checkboxes
13) Generate textfields
14) Simplest AJAX Example
15) Submit-driven AJAX

these examples are working correctly (Wizard example have few problem but it runs).
The remaining example I have attached the code inside the patch but they have few errors.

Mile23’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 30: ajaxexample-2102639-30.patch, failed testing. View results

Lal_’s picture

Documentation and fixed few errors but the problems still persist...

Lal_’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 33: ajaxexample-2102639-33.patch, failed testing. View results

Mile23’s picture

Assigned: Lal_ » Unassigned

The testbot says:

PHP Parse error:  syntax error, unexpected 'public' (T_PUBLIC) in /var/www/html/modules/contrib/examples/ajax_example/src/Form/AjaxExampleAutocompleteAuthor.php on line 137
xargs: php: exited with status 255; aborting
Lal_’s picture

Status: Needs work » Needs review
FileSize
107.56 KB
Lal_’s picture

The module still persist with the error mentioned in the #30

piyuesh23’s picture

Updated patch to add ajax example link to the toolbar & description page to list all the ajax examples. The patch also fixes the route names for the routes being listed on the description page.

Additionally, it would be great if we can outline the list of pending items around the port & update the summary/create child issues.

Lal_’s picture

Status: Needs review » Needs work

@piyuesh23
1) Wizard Example
2) Progress bar examples
3) Autocomplete examples
4) NodeFormAlter examples
5) Uniquecomplete examples
These examples are currently facing few errors and some have problems while running. Can you please take a look at the code...

Mile23’s picture

Could you be more specific about the errors, so that @piyuesh23 can zero in on them? Thanks.

Mile23’s picture

Status: Needs work » Needs review
FileSize
107.36 KB

A ton of cleanup and a minimal test.

I'll probably be splitting this out into the parts that work, with a follow-up to add the parts that currently don't.

This is the list of the routes from the test, showing which routes are reliable:

    // Click all the submit and cancel buttons.
    $routes = [
      'ajax_example.description' => [],
      'ajax_example.simplest' => [],
      // @todo progress bar example is broken.
      // 'ajax_example.progresssbar' => ['Submit'],
      // @todo not found
      // 'ajax_example.progresssbarProgress' => '',
      // @todo not found.
      // 'ajax_example.autocheckboxes' => '',
      'ajax_example.autotextfields' => ['Click Me'],
      'ajax_example.submit-driven-ajax' => ['Submit'],
      'ajax_example.dependent_dropdown' => ['Submit'],
      'ajax_example.dependent_dropdown_degrades' => ['Choose', 'OK'],
      'ajax_example.dependent_dropdown_degrades_nojava' => ['Choose', 'OK'],
      'ajax_example.dynamic_sections' => ['Choose', 'OK'],
      'ajax_example.dynamic_sections_nojava' => ['Choose'],
      'ajax_example.wizard' => ['Next step'],
      'ajax_example.wizardnojs' => ['Next step'],
      // @todo add-more has trouble with num_names.
      // 'ajax_example.addmore' => ['Submit'],
      // 'ajax_example.addmorenojs' => ['Submit'],
      // @todo advanced-commands does not render.
      // 'ajax_example.advanced' => ['Submit'],
      // @todo ajax-link is broken.
      // 'ajax_example.Ajaxlink' => [],
      'ajax_example.Ajaxlinkrender' => [],
      'ajax_example.Ajaxlinkcall' => [],
      // @todo simple autocomplete is 403.
      // 'ajax_example.AutocompleteSimplest' => [],
      // 'ajax_example.AutocompleteSimplestcallback' => [],
      'ajax_example.Autocompletenode' => [],
      'ajax_example.Autocompletenodecallback' => [],
    ];
Mile23’s picture

Forgot the interdiff.

Mile23’s picture

FileSize
44.78 KB

Hmm. Let's try that again.

Mile23’s picture

Assigned: Unassigned » Mile23

Still working on this...

Mile23’s picture

This patch removes quite a number of the examples, and we'll have a follow-up to add them back.

The interdiff is pretty huge. :-)

Mile23’s picture

FileSize
91.36 KB

What is it with me and interdiffs?

Mile23’s picture

Very minor code cleanup for simplest example.

Added two JS functional tests.

Mile23’s picture

Lots of pruning and improvements.

Mile23’s picture

More pruning, rearranging, making links work on pages, managing path parameters.

This is pretty close, and I'll likely commit it if the tests are green on the testbot. Then we'll start on the follow-ups.

  • Mile23 committed 1da320c on 8.x-1.x authored by AbhishekLal
    Issue #2102639 by AbhishekLal, Mile23, kerasai, piyuesh23, navneet0693,...
Mile23’s picture

navneet0693’s picture

Thanks @Mile23 for cleaning up and committing it.

Lal_’s picture

Ahh... Feels awesome... @Mile23 thank you for your help... @navneet0693 thank you for mentoring me...

  • Mile23 committed ebc4a65 on 8.x-1.x
    Issue #2102639: Remove usages of #prefix and #suffix per #18
    

Status: Fixed » Closed (fixed)

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