As follow up from provide a 'global' block administration interface here is a patch which makes

  1. the _block_rehash() function reusable (removes the global $theme_key) and
  2. removes the hardcoded $form_state['redirect'] = 'admin/build/block' in favor of a url argument (drupal_get_destination())

This simplifies the process to provide a blocks interface with 'by block' and 'by theme' functionality from a contributed module (see the discussion on that in the referenced issue).

Comments

profix898’s picture

Assigned: Unassigned » profix898
profix898’s picture

Nobody? Its a simple patch that doesn't hurt IMO.

spyderpie’s picture

i would test ... but it says version 6.x ... I'm at 5.1 ... can I put it there?

Julie

profix898’s picture

@spyderpie: The patch is for the development version (6.x) of Drupal and there is not much to test here. The patch doesnt provide any new functionality, it only rearranges the some small pieces of code in block.module. To test the patch you should install a development snapshot and play with the block administration. If you dont experience any difference with/without the patch then it is ready ...

profix898’s picture

... still needs review ...

spyderpie’s picture

Okay - give me about 2 days and I will test .... just got a lot going on .. (and two munchkins stealing my computer time! LOL)

profix898’s picture

StatusFileSize
new3.14 KB

Rerolled for latest HEAD.

profix898’s picture

... still applies ...

pwolanin’s picture

Category: task » bug
Priority: Normal » Critical

Without something like this, it doesn't seem possible for a module to remove a block it has previously declared via an API function - rather one would have to delete items from the {blocks} and {blocks_roles} tables, which seems a bit ugly. This is kind of blocking this issue: http://drupal.org/node/156626

profix898’s picture

@pwolanin: It seems you decided to delete blocks from the tables directly. I think a reusable block_rehash() would be useful in several locations and it is needed for being able to extend blocks administration in contributed modules. Otherwise we'd have to duplicate the whole function. Any chance to have this RTBC?

pwolanin’s picture

I'll look in more detail. Seems the original code neglects to delete form {block_roles} if a block goes away?

bdragon’s picture

Status: Needs review » Needs work

File to patch: modules/block/block.module
patching file modules/block/block.module
Hunk #1 succeeded at 210 (offset 57 lines).
Hunk #2 succeeded at 197 (offset 2 lines).
Hunk #3 FAILED at 205.
Hunk #4 FAILED at 231.
Hunk #5 FAILED at 254.
Hunk #6 FAILED at 514.
4 out of 6 hunks FAILED -- saving rejects to file modules/block/block.module.rej

Needs rerolled (Pre-split era?) and also needs to be rolled from the correct directory.

chx’s picture

Category: bug » task
Priority: Critical » Normal

I disagree this being a bug and especially disagree it being critical. Critical means a part of core is totally broken.

brianV’s picture

Version: 6.x-dev » 7.x-dev

Moving to 7.x

carlos8f’s picture

subscribing

seanburlington’s picture

This seems like an important missing piece of API to me

mr.baileys’s picture

The theme-key portion of this patch seems to have been implemented by #581118: Blocks admin user interface should not do theme switching

andypost’s picture

Is this still an issue?

seanburlington’s picture

If the function is usable externally it should be renamed as block_rehash()

elliotttf’s picture

StatusFileSize
new2.4 KB

The theme issue does appear to be fixed as mentioned above; however, I agree with #19 that if the goal is to make this function globally reusable it should be renamed to block_rehash().

I've attached a patch to accomplish this. Note that this patch will break any contrib modules that currently call _block_rehash. An alternative way around this (although not very clean) would be to leave _block_rehash() as is and create a new function block_rehash() that just calls _block_rehash().

elliotttf’s picture

Status: Needs work » Needs review
seanburlington’s picture

Status: Needs review » Reviewed & tested by the community

there is only a single module in contrib that uses the function so renaming should be managable

patch looks good to me

cd ~/drupal
cat CVS/Root
:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal
cvs -q up
find . | xargs grep -si _block_rehash
./modules/block/block.admin.inc:  $blocks = _block_rehash($theme);
./modules/block/block.module:function _block_rehash($theme = NULL) {
./modules/dashboard/dashboard.module:  $blocks = _block_rehash();
./modules/dashboard/dashboard.module: *   - blocks: An array of block objects from _block_rehash().
./modules/dashboard/dashboard.module: *   - block: A block object from _block_rehash().
webchick’s picture

Version: 7.x-dev » 8.x-dev

API change => Drupal 8.

seanburlington’s picture

Surely "private" functions don't form part of the API ??!

So effectively this is just adding to the API which should be OK - even after launch if it's too late for 7.0

EvanDonovan’s picture

Subscribing. I have noticed there are cases in which I want to change which blocks are available programmatically, and would like to have a more elegant way to do so than with a function that has a hardcoded variable.

dries’s picture

Status: Reviewed & tested by the community » Needs work

Does not apply against 8.x so setting to 'needs work' and asking for a re-test.

dries’s picture

Status: Needs work » Needs review

#20: block_rehash.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, block_rehash.patch, failed testing.

andypost’s picture

seems not valid for now so could be closed

internetdevels’s picture

Assigned: profix898 » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new5.3 KB
new4.42 KB

As task hasn't been closed I've prepared new patch.

andypost’s picture

Suppose better for d8 move this function to some manager method,
The function is not a part of API because starts from '_' so better not introduce api change here

internetdevels’s picture

StatusFileSize
new6.63 KB
new8.33 KB

New patch attached.

tim.plunkett’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
    @@ -121,4 +122,43 @@ public function getCategories() {
    +   * Returns an array of block class instances by theme.
    

    We need a better place to put this. It returns an array of block entities, while this is the manager for block plugins. I think a new class is needed.

  2. +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
    @@ -121,4 +122,43 @@ public function getCategories() {
    +  public function block_rehash($theme = NULL) {
    

    This needs to be blockRehash()

xjm’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2514998: Reduce fragility in the monolithic BlockListBuilder