I have developed a Drupal 8 module and named it "Next and previous link" The Drupal plug-in will allow the website visitors to jump on the next or previous post without going back to the main page to see all the posts. Drupal developers can use this plug-in for particular content types. Suppose, there are many large content bundles, then the developer can apply the plug-in for a specific bunch of content.
For example:-
I have a "Blog" content type and in this blog 100 pages (Nodes). A visitor comes on the website and reads blog number 56 (Node/56). We have to provide a next and previous button on the detail page to jump the next and previous blog.
This module is made on Drupal 8. Please help me to cover the security advisory policy.
Project link
https://www.drupal.org/project/nextpre
Git instructions
git clone --branch 8.x-1.x https://git.drupalcode.org/project/nextpre.git
PAReview checklist
https://pareview.sh/pareview/https-git.drupal.org-project-nextpre.git-8.x-1.x
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | Configure block Drupal 8 Test.png | 32.6 KB | rohitrajputsahab |
Comments
Comment #2
rohitrajputsahab commentedComment #3
rohitrajputsahab commentedComment #4
Ben Greenberg commentedI updated the Git instructions for non-maintainer users, and added a link to the PAReview checklist.
Automated Review
hook_help(). See https://www.drupal.org/docs/develop/documenting-your-project/module-docu..... Implementinghook_help()will also mean there will be content for your nextpre.module file, and you won't have to deal with the DrupalSecure warning about it being empty.nextpre/src/Plugin/Block/NextPreviousBlock.phpline 86: "NodeType::loadMultiple calls should be avoided in classes, use dependency injection instead". This can be fixed by changing the line to$node_types = $this->nodeTypeStorage->loadMultiple();Note that perfect adherence to Drupal Coding Standard is NOT a reason to block an application, except for total disregard of them. However, modules should follow them as closely as possible.
Manual Review
For example:
nextpre/src/Plugin/Block/NextPreviousBlock.phpline 14:use Drupal\Core\node\Entity\NodeType as NodeType;should be changed to:use Drupal\node\Entity\NodeType as NodeType;. However, if you fix the Automated Review warning on line 86, mentioned above, you can remove this line entirely.nextpre/src/Plugin/Block/NextPreviousBlock.php,generatePrevious(),generateNext(), andgenerateNextPrevious()need@paramand@returnDocBlocks.nbprojectfolder and.gitignorefile are being included in releases. Use.gitattributesto prevent this. Please see Creating a Project Release for more information.nbprojectfolder from the git index by using the commandgit rm -r --cached nbprojectand it will be removed from the repository after a commit and push. Note: if you don't include the "--cached" argument, the folder will also be deleted from your local directory!.gitignorefor thenbprojectfolder, you don't really need it in your repository. You can actually add ".gitignore" to the.gitignorefile. You can then do agit rm --cached .gitignoreto remove it from the index.The starred items (*) are fairly big issues and warrant going back to Needs Work. The rest of the comments in the code walkthrough are recommendations.
If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.
This review uses the Project Application Review Template.
Remember to change the status to Needs Review after you are done addressing the issues mentioned above.
Comment #5
rohitrajputsahab commentedI have resolved "Automated Review" and "Manual Review". Please check it again and let me know if any issue and other things is remaining.
Comment #6
Ben Greenberg commentedAutomated Review
Note that perfect adherence to Drupal Coding Standard is NOT a reason to block an application, except for total disregard of them. However, modules should follow them as closely as possible.
Manual Review
The starred items (*) are fairly big issues and warrant going back to Needs Work.
I can understand how you would think that the API documentation and comment standards doesn't apply to your project. However, even though the page looks like it's just for API documentation, the standards apply to all project code.
The missing
@paramand@returnthat I mention are just examples. You should read the entire page, and go through your code and make any necessary changes. Look at a few other projects, especially well established ones, to see how they apply the standards.You should try to put yourself in the position of someone with some knowledge of how Drupal works, but who is looking at your code for the first time. For example, imagine looking at this for the first time:
$created_time? Is it a date object, a string, an integer of a Unix timestamp...?$directionis the string 'next', but what other values does it take?Again, this is just one example. You should read the entire page, go through your code and make any necessary changes.
If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.
This review uses the Project Application Review Template.
After making changes, go to the PAReview checklist and
Repeat reviewto make sure they didn't introduce any new issues.Comment #7
avpadernoComment #8
Ben Greenberg commentedBy the way, you may find these projects helpful for developing Drupal projects. They will let you run the automation tests without having to commit your code to the repository:
Also, you may want to start following the best practices outlined in Commit messages - providing history and credit. Particularly the part about referencing issues in commit messages, and giving credit to other contributors who submitted patches.
Comment #9
avpadernoComment #10
rohitrajputsahab commentedAgain, I have fixed all problems as per the "Drupal Coding Standard". Please check it again and let me know if any issue and other things are remaining.
Comment #11
avpadernoThe priority doesn't change, since 3 weeks have not passed from the last review.
Comment #12
Ben Greenberg commentedAutomated Review
No issues found
Manual Review
Also confirmed by entering
<script>alert('test');</script>in all form fields created by the module.build()inNextPreviousBlock.phpreturns a non-empty array when there is no next and no previous link. This means the block is still added to the page even if there aren't any links to show. If this is not by design, then please look at the DocBlock of thebuild()method you are inheriting from to see what should be returned if the block should not be added to the page.generatePrevious()says it returns "A render array...", as doesgenerateNext(). However, the DocBlock forgenerateNextPrevious()says it returns "Find the alias of the next node." Also, it's possible for those methods to return an empty array.@paramdescriptions begin with the word "Get", which isn't correct usage in this context. Please look at the DocBlocks of some core and major contrib modules to see how they write their@paramdescriptions.The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.
Comment #13
Ben Greenberg commentedComment #14
rohitrajputsahab commentedCoding style & Drupal API usage
I have made all field required for cover 1, 2 and 3 point.
4. I changed the word "Get" and added as per the standard.
5. I have changed code in my file src/Plugin/Block/NextPreviousBlock.php vid to nid to resolved the node revisions things. Like UPDATE, DELETE and CREATE.
Everything is working fine.
Comment #15
rohitrajputsahab commentedComment #16
batkorwhat for the call parent method in 115, 120, 83 lines?
https://git.drupalcode.org/project/nextpre/blob/8.x-1.x/src/Plugin/Block...
https://git.drupalcode.org/project/nextpre/blob/8.x-1.x/src/Plugin/Block...
https://git.drupalcode.org/project/nextpre/blob/8.x-1.x/src/Plugin/Block...
why used
request_stackservice?If use
current_route_match,buildmethod change to:Not recomende using maxAge=0.
More info
More
https://git.drupalcode.org/project/nextpre/blob/8.x-1.x/src/Plugin/Block...
Recomended used cache-tag.
Example, don't checked
Add default value for
$directionparamhttps://git.drupalcode.org/project/nextpre/blob/8.x-1.x/src/Plugin/Block...
Method changed to:
Thank you for create this module.
Comment #17
batkorCheck node type before query in build method
https://git.drupalcode.org/project/nextpre/blob/8.x-1.x/src/Plugin/Block...
Comment #18
rohitrajputsahab commented@batkor
https://git.drupalcode.org/project/nextpre/commit/4775224831978ab0872b25...
I have changed my code as per your commit.
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Recommended used cache-tag.
Example, don't check
public function getCacheTags() {
return $current_node->getCacheTagsToInvalidate();
}
I can't change my code maxAge=0.
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return 0;
}
Comment #19
batkorhttps://git.drupalcode.org/project/nextpre/commit/4775224831978ab0872b25...
$nodereally an Node entity?For check use
if ($node instanceof Node) {Comment #20
rohitrajputsahab commented@batkor
For node check, I have added the below code.
https://git.drupalcode.org/project/nextpre/commit/90c2ae967f7c861f89f804...
use Drupal\node\NodeInterface;
if ($node instanceof NodeInterface
Comment #21
batkorWhere returns default value?
https://git.drupalcode.org/project/nextpre/blob/8.x-1.x/src/Plugin/Block...
Nitpick
I'm not sure if ParamConverterInterface uses in
request.I think instead
request.use
routeMatchComment #22
rohitrajputsahab commentedI have checked this is not working.
$node = $this->routeMatch->getParameter('node');
Added default value
https://git.drupalcode.org/project/nextpre/commit/52391e6a81c4a269af5740...
Comment #23
rohitrajputsahab commentedComment #24
rohitrajputsahab commentedComment #25
dakwamineHello rohit-drupal,
nextpre.module
The help is not translatable. Not everyone is speaking english. You should give the ability to anyone to contribute to your module translations using the standard system. My advice would be to put a translatable short description of the module and usage, and to include a link to any other documentation page.
src\Plugin\Block\NextPreviousBlock.php
build()
You need to allow only a set of routes before calling this and going further. Only allow
entity.node.canonical,entity.node.revisionand any other suitable routes for current route.Currently, it is not possible to use
$node = $this->routeMatch->getParameter('node');as suggested earlier. Indeed, this is not yet working on other routes thanentity.node.canonical, and this is tracked by this issue: #2730631: Upcast node and node_revision parameters of node revision routes ➡️ the returned value is inconsistent. So no need to change the$node = $this->request->attributes->get('node');line.getCacheMaxAge()
Why override this? Is it intended to make this block uncacheable by setting the value to 0? This seems not efficient. You should use cache tags: https://www.drupal.org/docs/8/api/cache-api/cache-tags.
Specifically, a simple cache tag for your block would be
node_list:A better solution, which could come as an enhancement, would be to implement a little system which tags using
node:id(e.g.node:15,node:214) when there are previous and next nodes (you already have their ids in the process of building the block, so it's just a few lines to refactor), andnode_listwhen the next node is not yet created.'next' and 'prev'
I would suggest using PHP const instead of string literals. This makes code more maintainable. Something like:
Other considerations
Comment #26
rohitrajputsahab commentednextpre.module
I have added translatable functioanllity in "nextpre.module" file.
src\Plugin\Block\NextPreviousBlock.php
build()
I removed "$node = $this->request->attributes->get('node');" and using "$node = $this->routeMatch->getParameter('node');"
getCacheMaxAge()
Removed getCacheMaxAge and used "https://www.drupal.org/docs/8/api/cache-api/cache-tags" getCacheTags()
'next' and 'prev'
used PHP const instead of string literals.
Comment #27
avpadernoThank you for your contribution! I am going to update the project to opt it into security coverage.
These are some recommended readings to help with excellent maintainership:
You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
I thank all the dedicated reviewers as well.
Comment #28
rohitrajputsahab commented@kiamlaluno
Thank you so much