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 ;)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lukas von Blarer’s picture

Assigned: Unassigned » Lukas von Blarer

Working on this...

Lukas von Blarer’s picture

Status: Active » Needs review
FileSize
20.69 KB

I created a first port. Please review it carefully since this is my first D8 module :)

We are still missing some methods of the new cache API. But the basic functionality is there.

Mile23’s picture

Thanks, Lukas.

Just a few things thus far...

  1. +++ b/cache_example/cache_example.info.yml
    @@ -0,0 +1,5 @@
    +package: Example modules
    

    Just 'Examples'.

  2. +++ b/cache_example/cache_example.module
    @@ -0,0 +1,185 @@
    +
    +   // Try to load the files count from cache. This function will accept two
    +   // arguments:
    +   // - cache object name (cid)
    +   // - cache bin, the (optional) cache bin (most often a database table) where
    +   //   the object is to be saved.
    +   //
    +   // cache_get() returns the cached object or FALSE if object does not exist.
    +  if ($cache = cache_get('cache_example_files_count')) {
    

    Wrong indent on the comments.

  3. +++ b/cache_example/lib/Drupal/cache_example/Forms/CacheExampleForm.php
    @@ -0,0 +1,237 @@
    +use Drupal\Core\Session\UserSession;
    

    NetBeans warns me that UserSession isn't used in this file.

  4. +++ b/cache_example/lib/Drupal/cache_example/Forms/CacheExampleForm.php
    @@ -0,0 +1,237 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function buildForm(array $form, array &$form_state) {
    

    Since this is a documentation project, we want to avoid {@inheritdoc}. Something like: "We're overriding this method because..."

  5. +++ b/cache_example/lib/Drupal/cache_example/Forms/CacheExampleForm.php
    @@ -0,0 +1,237 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function submitForm(array &$form, array &$form_state) {
    +
    +  }
    

    I guess this is coming later...

Mile23’s picture

Status: Needs review » Needs work
Berdir’s picture

2. The main problem here is actually that it still references cache_get().

4. @inheritdoc is the core standard. This is a cache example module, we don't really need to explain here how a form works? It's not overriding some default logic, it's implementing the method that each form has to, there's nothing special about it's form handling.

5. That might be the only special thing (re form handling) it has. It doesn't have a main save/submit button, just a few specific ones that have their own method. But FormInterface mandates that each form class must have a submitForm() method. That said, we should add a comment inside it why it's empty.

Mile23’s picture

@Berdir: If you're a newbie you don't already know that buildForm is unrelated to dealing with caches. It's the same problem as submitForm.

Lukas von Blarer’s picture

Issue summary: View changes
FileSize
15.12 KB

I did the requested changes except for the {@inheritdoc} request. It does not improve the example of the cache API but the form API. This should be done inside the form_example module, not in the cache_example module.

Further I removed the old page callback and also removed the unneccessary information inside cache_example_menu(). I also added @todos for the missing examples in the cache API. Lets do this in a separate issue.

Lukas von Blarer’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: 2102645-cache_example-d8-port-7.patch, failed testing.

Mile23’s picture

Status: Needs work » Needs review
Mile23’s picture

Berdir’s picture

Status: Needs review » Fixed

Should this be set to fixed then? :)

Mile23’s picture

Indeed it should. :-)

sdelbosc’s picture

On /admin/modules page this module does not appear in the same group as the other examples.

sdelbosc’s picture

tsphethean’s picture

Status: Fixed » Reviewed & tested by the community

Looks good to me!

Mile23’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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