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

Problem/Motivation

We have the Drupal 7 version of node_access_example, but no Drupal 8 version.

Let's port it.

Proposed resolution

Port the module.

How To Review

Perform the following steps, and make a note of which items are acceptable and which are not.

  • Apply the patch.
  • Enable the module.
  • Verify that there is a menu link to the module's description page visible on the front page.
  • Verify that there is an examples toolbar entry for the module.
  • Use the module. Try to follow its instructions.
  • Run the tests, both through the Testing module UI, and also using run-tests.sh: https://www.drupal.org/node/645286
  • Read the Examples module checklist: #2209627: [meta] Module Checklist for Examples Make sure the ported module meets these criteria.
  • Read the in-code documentation to verify that it is correct and comprehensible.
CommentFileSizeAuthor
#36 2102667-36.patch29.2 KBmichaellenahan
#33 2102667-33.patch29.17 KBmichaellenahan
#31 2102667_31.patch29.17 KBnavneet0693
#31 interdiff-27-31.txt2.63 KBnavneet0693
#27 2102667-27.patch28.77 KBnavneet0693
#27 interdiff-24-27.txt20.1 KBnavneet0693
#26 port-2102667-26.patch30.28 KBdpagini
#24 interdiff.txt1.9 KBMile23
#24 2102667_24.patch30.29 KBMile23
#23 port-2102667-23.patch30.25 KBdpagini
#21 port-2102667-21.patch30.24 KBdpagini
#19 port-2102667-19.patch539 bytesdpagini
#13 node_access_example-2102667-13.patch30.28 KBnavneet0693
#13 interdiff-13.txt24.42 KBnavneet0693
#8 node_access_example_2102667-8.patch49.02 KBnavneet0693
#8 interdiff.txt19.13 KBnavneet0693
#4 node_access_example_2102667_4.patch16.26 KBvordude
#2 node_access_example_2102667_2.patch16.25 KBvordude
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

javisr’s picture

Assigned: Unassigned » javisr
Issue summary: View changes

i will work on it.

vordude’s picture

Assigned: javisr » vordude
Status: Active » Needs work
FileSize
16.25 KB

So. I realize i didn't take the steps outlined in #1880976: [meta] Port examples (including submodules) to D9.4+ but this first patch gives a good start to step 4 (Port example code to D8).

A functional port of the D7 version of the code. Which made a bit more sense to me when realizing that some things would have to be done completely different in the D8 version than the D7 version.

I fiddled for awhile to figure out how to add an additional property to the node the way it was possible with previous versions of drupal adding a form field with hook_form_alter. I wasn't sure that was easily possible, so I added a field to the article content type. This is probably not an acceptable dependency, but it's a start to get a functional version working.

joshi.rohit100’s picture

+++ b/node_access_example/src/Controller/NodeAccessExampleController.php
@@ -0,0 +1,63 @@
+    $content['info'] = array('#markup' => t('This example shows how a module can use the Drupal node access system to allow access to specific nodes. You will need to look at the code and then experiment with it by creating nodes, marking them private, and accessing them as various users.') . '</div>');
+    $content['count'] = array('#markup' => t('There are currently @num private nodes in the system @num_personal are yours.', array('@num' => $this->privateNodeCount(FALSE), '@num_personal' => $this->ownPrivateNodeCount())) . '</div>');
+    $content['owner'] = array('#markup' => t('You have access to @num private nodes.', array('@num' => $this->privateNodeCount())) . '</div>');
+    $content['list'] = array(

Should be $this->t

Also we don't use private in Drupal, so change visibility from private.

vordude’s picture

navneet0693’s picture

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

Assigned: Unassigned » navneet0693
navneet0693’s picture

Status: Needs review » Needs work

Adding tests, entry in example.module, improving code.

navneet0693’s picture

Status: Needs review » Needs work

The last submitted patch, 8: node_access_example_2102667-8.patch, failed testing.

The last submitted patch, 8: node_access_example_2102667-8.patch, failed testing.

Mile23’s picture

Issue summary: View changes
+++ b/interdiff.txt
@@ -0,0 +1,522 @@
+     'js_example' => 'js_example.info',
++    'node_access_example' => 'node_access_example.description',
+     'node_type_example' => 'config_node_type_example.description',

Included interdiff in patch. How to make a patch: https://www.drupal.org/node/707484

Also whitespace errors and so forth.

Updating issue summary with how to review a patch like this.

navneet0693’s picture

HI @Mile23, accidentally included, interdiff in patch. I am recreating the patch.

navneet0693’s picture

navneet0693’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: node_access_example-2102667-13.patch, failed testing.

Torenware’s picture

Looks like you have a syntax error:

05:50:08 PHP Parse error:  syntax error, unexpected '=' in /var/www/html/modules/examples/node_access_example/src/Tests/NodeAccessExampleTest.php on line 300
05:50:08 
05:50:08 Parse error: syntax error, unexpected '=' in /var/www/html/modules/examples/node_access_example/src/Tests/NodeAccessExampleTest.php on line 300

See if fixing this makes your patch run. This is a simpletest (how can you tell? Because it's in MODULE_NAME/src/Testing). First, try running it on the admin/config/development/testing. Usually, if this works, your patch will run under the testbot. In the rare cases it doesn't, you might also use the run-test.sh tool, but most of the time, you won't really need to. This error should surface easily.

navneet0693’s picture

@Torenware, thanks for pointing out the error :) working on it.

Mile23’s picture

Assigned: navneet0693 » Unassigned

Generally unassigning issues. Please re-assign yourself as desired.

dpagini’s picture

Status: Needs work » Needs review
FileSize
539 bytes

Attempting a re-roll of this to apply cleanly and fix the Simpletest error. I wasn't exactly sure what the problem-child line from #16 was doing, so I referenced back to an old test, and updated the code to match that. We'll see how this does. I did not add anything to this, just was looking for an examples module for node_access and stumbled upon this, so thought I'd apply it and see if I could help get it posted.

Mile23’s picture

Status: Needs review » Needs work

Thanks, but that patch looks a little incomplete...

dpagini’s picture

Status: Needs work » Needs review
FileSize
30.24 KB

Ugh, embarrassed I posted that w/o looking. I guess I haven't posted a patch with a new file(s) in it before, so I had to look up how to do it. Sorry about that, I hope this one is better.

Status: Needs review » Needs work

The last submitted patch, 21: port-2102667-21.patch, failed testing. View results

dpagini’s picture

Mile23’s picture

Status: Needs work » Needs review
FileSize
30.29 KB
1.9 KB

Moved the test to BrowserTestBase, because it's better. :-)

The test now fails instead of having a crash.

I'm not sure what to do about the cronRun() line.

Interdiffs are very helpful, but optional. Still tho... :-) https://www.drupal.org/documentation/git/interdiff

Status: Needs review » Needs work

The last submitted patch, 24: 2102667_24.patch, failed testing. View results

dpagini’s picture

FileSize
30.28 KB

Yeah, attached is as far as I can get... I just don't think this code is working actually. My test is failing when my user goes to the search page, and tries to find private nodes. It's expecting the user can only find the node they published, so 1 search result, but instead the site is returning 3 nodes (all the private nodes) and that's failing the tests. These tests need a lot of work, and I'm sure there will be some work after this cron situation is figured out.
Anyways, I'm trying to get into node_access with a project I'm working on now, so if I learn along the way what's wrong with this code, I'll come back and take a look at it again.
This does not have Mile23's latest additions in it if anyone comes along to work on this.
I'll have to look into how to create and post the interdiff files. Thanks for the link!

navneet0693’s picture

Changed the ambiguous code in tests and with few coding standard fixes.

navneet0693’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 27: 2102667-27.patch, failed testing. View results

Mile23’s picture

My intuition is that node_access_example_install() isn't an up-to-date way of doing things.

We need to have a way to put this in the config/ folder.

navneet0693’s picture

Status: Needs review » Needs work

The last submitted patch, 31: 2102667_31.patch, failed testing. View results

michaellenahan’s picture

The patch in #31 needed a reroll.

michaellenahan’s picture

Status: Needs work » Needs review

Changing status to "needs review" to start the test runner.

Status: Needs review » Needs work

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

michaellenahan’s picture

Hmm. I don't know why I get the error:

FATAL Drupal\Tests\node_access_example\Functional\NodeAccessExampleTest: test runner returned a non-zero

https://www.drupal.org/pift-ci-job/918676

... is it because of the coding standards violation, I wonder.

node_access_example/node_access_example.module
line 121 Doc comment short description must be on a single line, further text should be a separate paragraph

... let's see ...

michaellenahan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 36: 2102667-36.patch, failed testing. View results

michaellenahan’s picture

So, it wasn't anything to do with the coding standards violation ... https://www.drupal.org/pift-ci-job/919420 ... I don't know what's causing the error.