Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#36 | 2102667-36.patch | 29.2 KB | michaellenahan |
#33 | 2102667-33.patch | 29.17 KB | michaellenahan |
#31 | 2102667_31.patch | 29.17 KB | navneet0693 |
#31 | interdiff-27-31.txt | 2.63 KB | navneet0693 |
#27 | 2102667-27.patch | 28.77 KB | navneet0693 |
Comments
Comment #1
javisr CreditAttribution: javisr commentedi will work on it.
Comment #2
vordude CreditAttribution: vordude at Lullabot commentedSo. 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.
Comment #3
joshi.rohit100Should be $this->t
Also we don't use private in Drupal, so change visibility from private.
Comment #4
vordude CreditAttribution: vordude at Lullabot commentedComment #5
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #6
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #7
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedAdding tests, entry in example.module, improving code.
Comment #8
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #11
Mile23Included 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.
Comment #12
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedHI @Mile23, accidentally included, interdiff in patch. I am recreating the patch.
Comment #13
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #14
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #16
Torenware CreditAttribution: Torenware as a volunteer commentedLooks like you have a syntax error:
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.
Comment #17
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commented@Torenware, thanks for pointing out the error :) working on it.
Comment #18
Mile23Generally unassigning issues. Please re-assign yourself as desired.
Comment #19
dpagini CreditAttribution: dpagini as a volunteer commentedAttempting 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.
Comment #20
Mile23Thanks, but that patch looks a little incomplete...
Comment #21
dpagini CreditAttribution: dpagini as a volunteer commentedUgh, 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.
Comment #23
dpagini CreditAttribution: dpagini as a volunteer commentedComment #24
Mile23Moved 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
Comment #26
dpagini CreditAttribution: dpagini as a volunteer commentedYeah, 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!
Comment #27
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedChanged the ambiguous code in tests and with few coding standard fixes.
Comment #28
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #30
Mile23My 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.Comment #31
navneet0693 CreditAttribution: navneet0693 as a volunteer and at QED42 commentedComment #33
michaellenahan CreditAttribution: michaellenahan commentedThe patch in #31 needed a reroll.
Comment #34
michaellenahan CreditAttribution: michaellenahan commentedChanging status to "needs review" to start the test runner.
Comment #36
michaellenahan CreditAttribution: michaellenahan commentedHmm. 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 ...
Comment #37
michaellenahan CreditAttribution: michaellenahan commentedComment #39
michaellenahan CreditAttribution: michaellenahan commentedSo, 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.