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.

Test process :
-Apply patch
-Refresh Cache
-Check that block pages like :
-- /admin/structure/block/demo/bartik
-- /admin/structure/block/demo/seven
are still ok

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pdrake’s picture

Assigned: Unassigned » pdrake
pdrake’s picture

Status: Active » Needs review
FileSize
4.85 KB
pdrake’s picture

pdrake’s picture

kim.pepper’s picture

Status: Needs review » Needs work
Issue tags: +WSCCI-conversion

The last submitted patch, drupal-convert_block_admin_demo-1987636-4.patch, failed testing.

kim.pepper’s picture

Issue tags: +Needs reroll
vijaycs85’s picture

Status: Needs work » Needs review
FileSize
7.58 KB

Re-rolling...

dawehner’s picture

Assigned: pdrake » Unassigned

The other theme is stilled picked up, during manual testing.

+++ b/core/modules/block/block.moduleundefined
@@ -229,9 +225,8 @@ function block_page_build(&$page) {
+  if ($item['path'] != 'admin/structure/block/demo/%' || !isset($item['map'][4]) || $item['map'][4] != $theme) {

Can we add a documentation what's going on here?

+++ b/core/modules/block/block.moduleundefined
@@ -251,26 +246,23 @@ function block_page_build(&$page) {
+      '#href' => 'admin/structure/block' . (config('system.theme')->get('default') == $theme ? '' : '/list/' . $theme),

Config is a service so let's use Drupal::config() instead.

+++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.phpundefined
@@ -0,0 +1,36 @@
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

This dependency is not needed

+++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.phpundefined
@@ -0,0 +1,36 @@
+   *

just remove this empty line.

+++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.phpundefined
@@ -0,0 +1,36 @@
+    drupal_add_css(drupal_get_path('module', 'block') . '/block.admin.css');

Can you open a follow up to convert this into a library?

+++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.phpundefined
@@ -0,0 +1,36 @@
+    return new Response();

Can't we also just return '' ?

star-szr’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll
vijaycs85’s picture

Status: Needs work » Needs review
FileSize
7.78 KB
dawehner’s picture

Final nitpick: There should be an empty line between the last two } } of a file.

vijaycs85’s picture

Thanks for the review @dawehner. Updated Coding standard page to reflect this standard (https://drupal.org/node/608152/revisions/view/2686632/2739353).

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you very much!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/block/block.admin.incundefined
@@ -9,19 +9,6 @@
-  return array(
-    '#attached' => array(
-      'css' => array(drupal_get_path('module', 'block') . '/css/block.admin.css'),
-    ),
-  );

+++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.phpundefined
@@ -0,0 +1,38 @@
+    drupal_add_css(drupal_get_path('module', 'block') . '/block.admin.css');
+    return '';

We should be return the same array as before... using drupal_add_css in a controller should not be done.

pguillard’s picture

Assigned: Unassigned » pguillard
pguillard’s picture

Assigned: pguillard » Unassigned
Status: Needs work » Needs review
FileSize
7.08 KB

I removed that changes to the patch.

helenkim’s picture

pguillard’s picture

FileSize
1.25 KB

Forgot to put the interdiff (My First git diff interdiff :-)) , here it is.

helenkim’s picture

Check the #17's patch from #15. It looks O.K. Thanks you.

pguillard’s picture

rtbc ?

kim.pepper’s picture

Status: Needs review » Needs work
FileSize
84.67 KB
21.53 KB

I found a bug.

Steps to reproduce:

  • click on seven tab (path is /admin/structure/block/list/block_plugin_ui%3Aseven)
  • click on 'demonstrate block regions'
  • see a mostly blank screen, no regions demo'd (see screenshot)
  • click 'Exit block region demonstration' (path is /admin/structure/block/list/seven)
  • get a 'Page not found' error (see screenshot)

Seems to be an issue with paths and the non-default theme.

seven-block-demo.png

page-not-found.png

kim.pepper’s picture

Issue tags: +Needs tests

Flagging as "needs tests" as this wasn't caught by the current tests.

AjitS’s picture

Status: Needs work » Needs review
AjitS’s picture

Status: Needs review » Needs work

Changed the status by mistake. Sorry.

ygerasimov’s picture

I see the issue with Seven theme and blocks demo described in #22 even without applying any patches. It is a separate bug.

Opened issue #2042879: Theme Seven has "Demonstrate block regions" broken. Shall this new issue be blocking this one? I believe so.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
5.57 KB

I believe the bug described in #22 was resolved when I revamped the Block UI.
Anyway, here's a reroll with some fixes. The old patch didn't apply, so no interdiff.

jibran’s picture

Status: Needs review » Needs work

Some minor issues.

  1. +++ b/core/modules/block/lib/Drupal/block/Access/DemoThemesAccessCheck.php
    @@ -0,0 +1,33 @@
    +    return drupal_theme_access($request->attributes->get('theme'));
    

    :S

     function drupal_theme_access($theme) {
      if (is_object($theme)) {
        return !empty($theme->status);
      }
      else {
        $themes = list_themes();
        return !empty($themes[$theme]->status);
      }
    }

    Why are we depending on theme.inc? We can easily write the logic here.

  2. +++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.php
    @@ -0,0 +1,39 @@
    +  public function demo(Request $request) {
    ...
    +    $theme = $themes[$request->attributes->get('theme')];
    

    This doesn't make sense. $request->attributes->get('theme') should be passed to function not $request according to route definition. Am I missing something?

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

2 is definitely a good point. I'll sleep on 1.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
8.53 KB
7 KB

Okay, I did both of #28.
It turns out we had duplicate access checkers, so I simplified all of that.

Status: Needs review » Needs work

The last submitted patch, block-1987636-30.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
708 bytes
8.59 KB

Thank goodness for test coverage.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Well now it looks nice and clear.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

jibran’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
8.59 KB

3-way merge

vijaycs85’s picture

+1 on RTBC.

jibran’s picture

Assigned: tim.plunkett » Unassigned
FileSize
1000 bytes
8.66 KB

Replaced t with $this->t in AdminController on @alexpott suggestion.

Status: Reviewed & tested by the community » Needs work
Issue tags: -WSCCI-conversion

The last submitted patch, drupal8.block-module.1987636-37.patch, failed testing.

disasm’s picture

Status: Needs work » Needs review
Issue tags: +WSCCI-conversion
dawehner’s picture

+++ b/core/modules/block/block.module
@@ -214,9 +210,10 @@ function block_page_build(&$page) {
+  // Make sure the blocks are not getting rendered for demo page
+  // or theme specific site building page.
+  if ($item['path'] != 'admin/structure/block/demo/%' || !isset($item['map'][4]) || $item['map'][4] != $theme) {

Can't we just check of if (\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME) != 'block_admin_demo' ?

xjm’s picture

Thanks for your work on this issue! Please see #1971384-43: [META] Convert page callbacks to controllers for an update on the routing system conversion process.

disasm’s picture

Status: Needs review » Needs work
kgoel’s picture

Assigned: Unassigned » kgoel
kgoel’s picture

Status: Needs work » Needs review
FileSize
3.76 KB

Did reroll first and after bot passes than i will be working on fixes.

Status: Needs review » Needs work

The last submitted patch, block-conversion-1987636-44.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
  1. +++ b/core/modules/block/block.module
    @@ -134,14 +134,6 @@ function block_menu() {
    -      'theme callback' => '_block_custom_theme',
    -      'theme arguments' => array($key),
    

    I think you'll need to leave this until #1954892: Replace 'theme callback' and hook_custom_theme() with a clean theme negotiation system is in.

  2. +++ b/core/modules/block/block.routing.yml
    @@ -1,7 +1,7 @@
    -    _content: '\Drupal\block\Controller\BlockController::demo'
    +    _content: '\Drupal\block\Controller\AdminController::demo'
    
    +++ b/core/modules/block/lib/Drupal/block/Controller/AdminController.php
    @@ -0,0 +1,39 @@
    +class AdminController extends ControllerBase {
    
    +++ /dev/null
    @@ -1,23 +0,0 @@
    -class BlockController {
    

    I think this can reasonably leave this as BlockController

kgoel’s picture

jibran’s picture

Status: Needs review » Needs work
+++ b/core/modules/block/lib/Drupal/block/Controller/BlockController.php
@@ -7,17 +7,33 @@
-    return block_admin_demo($theme);

Removal of this function from block.admin.inc file is missing.

kgoel’s picture

Assigned: kgoel » Unassigned
Status: Needs work » Needs review
FileSize
713 bytes
3.3 KB
jibran’s picture

Status: Needs review » Reviewed & tested by the community

It is good to go.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/block/block.module
    @@ -135,7 +135,6 @@ function block_menu() {
    -      'title' => check_plain($theme->info['name']),
    
    +++ b/core/modules/block/lib/Drupal/block/Controller/BlockController.php
    @@ -7,17 +7,33 @@
    +      '#title' => $this->t($themes[$theme]->info['name']),
    

    This is switched from check_plain to t(), why? Should probably be String::checkPlain

  2. +++ b/core/modules/block/lib/Drupal/block/Controller/BlockController.php
    @@ -7,17 +7,33 @@
    +   *   THe name of the theme.
    

    Wrongly capitalized H in THe

kgoel’s picture

Status: Needs work » Needs review
FileSize
1014 bytes
3.31 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

The feedback got adressed

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/block/block.module
@@ -193,9 +191,10 @@ function block_page_build(&$page) {
+  // Make sure the blocks are not getting rendered for demo page
+  // or theme specific site building page.
+  if ($item['path'] != 'admin/structure/block/demo/%' || !isset($item['map'][4]) || $item['map'][4] != $theme) {

Lets check the route name here instead of path. This formulation looks fragile. I think the new if means that $item['map'][4] == $theme then blocks will not be rendered... regardless of what is in $item['path'].

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
2.59 KB
4.5 KB
4.33 KB

We can just use the route name.

I also added tests, because we were missing a use statement, which caused the page to fatal.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/block/block.module
@@ -193,9 +192,7 @@ function block_page_build(&$page) {
+  if (\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME) != 'block.admin_demo') {

This look questionable because we where ignoring the parameter but tim assured me we don't care and reviewing further that seems true.

This looks pretty straight forward. Back to RTBC with the assumption testbot comes back green.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed c9e8fe3 and pushed to 8.x. Thanks!

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.