Part of #1971384: [META] Convert page callbacks to controllers

For instructions on how to convert a page callback into a controller, see the WSCCI Conversion Guide.

Files: 
CommentFileSizeAuthor
#3 node-node_add_controller-1987760-3.patch7.64 KBInternetDevels
FAILED: [[SimpleTest]]: [MySQL] 56,090 pass(es), 10 fail(s), and 0 exception(s).
[ View ]

Comments

Assigned:Unassigned» damiankloip

I'll take this one.

As this issue hasn`t been fixed yet we are going to work today with this issue during Code Sprint UA.

Assigned:InternetDevels» Unassigned
Status:Active» Needs review
Issue tags:+CodeSprintUA
StatusFileSize
new7.64 KB
FAILED: [[SimpleTest]]: [MySQL] 56,090 pass(es), 10 fail(s), and 0 exception(s).
[ View ]

Patch attached.

Issue tags:-CodeSprintUA

Great stuff!

+++ b/core/modules/node/lib/Drupal/node/Controller/NodeAddController.phpundefined
@@ -0,0 +1,47 @@
+class NodeAddController {

I guess on the longrun this controller will be receive some service, so let's implement ControllerInterface already.

+++ b/core/modules/node/lib/Drupal/node/Controller/NodeAddController.phpundefined
@@ -0,0 +1,47 @@
+   * @return array
+   *   A render array for a list of the node types that can be added; however, if
+   *   there is only one node type defined for the site, the function redirects
+   *   to the node add page for that one node type and does not return at all.

Let's also document the redirect response.

+++ b/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.phpundefined
@@ -24,19 +26,19 @@ class ListingEmpty extends AreaPluginBase {
     if (!$empty || !empty($this->options['empty'])) {
+      $access = new NodeAddAccess();

Shouldn't we inject this into the class using create()? On the longrun this class will have dependencies so it needs dependency injection.

+++ b/core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.phpundefined
@@ -24,19 +26,19 @@ class ListingEmpty extends AreaPluginBase {
+        '#access' => $access->access(new Route('/node'), \Drupal::request()),

\Drupal::requesty() can then also be injected. Nice trick btw.!

+++ b/core/modules/node/node.routing.ymlundefined
@@ -0,0 +1,8 @@
+    ¶
\ No newline at end of file
+++ b/core/modules/node/node.services.ymlundefined
@@ -0,0 +1,6 @@
\ No newline at end of file

Let's remove the whitespace and add a new line and the end of a file.

+++ b/core/modules/node/node.services.ymlundefined
@@ -0,0 +1,6 @@
+    arguments: ['@plugin.manager.entity']

You don't use the entity manager in the NodeAddAccess controller, is that on purpose?

Status:Needs review» Needs work

The last submitted patch, node-node_add_controller-1987760-3.patch, failed testing.

Status:Needs work» Closed (duplicate)

Status:Closed (duplicate)» Active

The other issue is correct to convert the node_add_page() callback. This issue is to port the node_add() callback i.e. 'node/add/%node_type'. So right issue, wrong patch :)

Status:Active» Closed (duplicate)

I'm going to roll the actual conversion of node_add into #1987762: Convert node_add_page() to a new style controller, as it will conflict quite a bit. So let's close this one again.