Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alberto56’s picture

Status: Active » Needs review
FileSize
16.04 KB

Here is a patch

pcambra’s picture

Status: Needs review » Needs work

Blocks are plugins now and the code above will need to be adapted.
Change notice: http://drupal.org/node/1880620

pcambra’s picture

Just an update of progress, mostly some thoughts on this

I guess we need an example of Derivatives too: http://drupal.org/node/1653226

Also the usage shown in the example module for hook_block_list_alter is quite weird, that hook has been removed in the plugin conversion by a hook_block_access so I guess we need to alter the example.

Additionally, hook_block_view_alter() has been refurbished a little in favor of hook_block_view_ID_alter() and hook_block_view_NAME_alter() but it remains around so we'd need the three of them included.

Related: #1874576: Improve the documentation and naming of hook_block_view_alter() hooks

pcambra’s picture

ybabel’s picture

Status: Needs work » Needs review
FileSize
16.04 KB

For the Drupal Global Sprint I worked on porting block example module to Drupal 8.

The 3 blocks works (empty / configurable_text / uppercase).

I did not found how to translate all the plugin anotations. Theses ones are not yet recognized :

    'region' => 'sidebar_first',  // Not usually provided.
    'visibility' => BLOCK_VISIBILITY_LISTED,  // Not usually provided.
    'pages' => 'node/*', // Not usually provided here.

I did not found how to implement block_example_block_view_alter correctly.
I tried something like that :

function block_example_block_view_alter(array &$build, \Drupal\block\Plugin\Core\Entity\Block $block) {
  if ($block->getPlugin() instanceof ExampleUppercaseBlock) {
    $build['#title'] = drupal_strtoupper($build['#title']);
  }
}

Tests not ported yet.

alberto56’s picture

Status: Needs review » Needs work

@ybabel

thanks. However you might have provided the wrong file: the patch provided is identical to the one in comment #1.

ybabel’s picture

Status: Needs work » Needs review
FileSize
9.76 KB

right ! my mistake.
here is the good patch

Status: Needs review » Needs work

The last submitted patch, 1630760-2-block-example-module.patch, failed testing.

ybabel’s picture

my patch didn't work because DBTNG and page_example are outdated ... I didn't work on them though.

But it work.

ybabel’s picture

Status: Needs work » Needs review
FileSize
13.28 KB

tests added, and patch updated

Status: Needs review » Needs work

The last submitted patch, 1630760-3-block-example-module.patch, failed testing.

ybabel’s picture

Status: Needs work » Needs review
FileSize
16.64 KB
rfay’s picture

Status: Needs review » Needs work

The last submitted patch, 1630760-4-block-example-module.patch, failed testing.

marvil07’s picture

Assigned: Unassigned » marvil07
Status: Needs work » Needs review
FileSize
16.12 KB
12.04 KB

Several changes to pass tests again.

  • Added type key to .info.yml file.
  • Modified hook_block_view_alter() to reflect the new type of the second parameter. Also re-insert the behaviour from D7 version.
  • Used Drupal\block_example\Plugin\Block namespace instead of Drupal\block_example\Plugin\block\block.
  • Show how to use set cache.
  • Remove blockAccess() implementations since parent class does the same.
  • Use blockBuild() instead of build(), since that's the common case.
  • Changed tests to use 'setting[label]' on block settings form pages.
  • Also some minor code standards and documentation related changes.

This will probably need another round of documentation changes, but it's running tests locally, let's see what bot thinks.

PS: Also, I fixed first the other already added modules related with the type key on info files change.

marvil07’s picture

FileSize
5.31 KB
11.87 KB

Some final changes for test to re-try before adding it.

  • region, visibility and pages keys from D7 hook_block_info() does not have an equivalent on D8 because blocks does not know about the context it will be used in.
  • Some minor varible names changes to improve readability.

Status: Needs review » Needs work

The last submitted patch, 1630760-16.patch, failed testing.

marvil07’s picture

Status: Needs work » Needs review

#16: 1630760-16.patch queued for re-testing.

marvil07’s picture

Status: Needs review » Fixed

Last patch added to 8.x-1.x.

Thank you all for the contributions here!

Also special thanks to timplunkett and xjm for the final hints ;-)

Status: Fixed » Closed (fixed)

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