Problem/Motivation

The current behaviour of the Dashboard controller only allow to render blocks of type block content.

Steps to reproduce

Try to add a custom block id in the hook_farm_dashboard_panes() and the controller will return Call to a member function getPlugin() on null

Proposed resolution

Implement a solution to render custom blocks in addition to content blocks.

Remaining tasks

- Add new key in hook_farm_dashboard_panes to manage custom blocks.
- Implements the behaviour to render custom blocks in the dashboard controller.

Related issues

Dashboard asset search block #81

Issue fork farm-3236712

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

evamtinez’s picture

evamtinez created an issue.

evamtinez’s picture

Added new key to hook_farm_dashboard_panes() to differentiate content blocks from plugin blocks and used that key to render the custom blocks in the dashboard controller.

evamtinez’s picture

Status: Active » Needs review
m.stenta’s picture

Thanks @evamtinez! This looks good to me! I'll wait to see if @paul121 has any thoughts before merging this.

Also: since most of our existing blocks are plugins, I think we could refactor those to use this approach, rather than providing config entities.

m.stenta’s picture

Hmm, on second thought - should we just refactor our existing code to use plugins ALWAYS? That was the original intention.

And then maybe we punt on supporting blocks created via the UI (config entities) until we have a full-featured dashboard builder based on Layout Builder? Just thinking out loud...

What do you think @paul121?

m.stenta’s picture

Ah hmm now that I look closer at our existing blocks, I think we will need to keep support for config entities too... because our dashboard_map block has some settings. So maybe we will need both mechanisms anyway.

m.stenta’s picture

With that in mind, I think this is good to go! I'll just wait to give @paul121 a chance to review.

I'll prepare a follow-up commit that refactors some of our dashboard blocks to use the block_plugin approach instead of block + config entity.

Thanks again @evamtinez!

m.stenta’s picture

Status: Needs review » Needs work

@evamtinez - Ah actually I'm not sure if this is working as expected.

I tried using this approach for our "Metrics" dashboard block, but I'm getting the following error when I view the dashboard:

User error: "0" is an invalid render array key in Drupal\Core\Render\Element::children()

Setting this back to "Needs work".

m.stenta’s picture

Status: Needs work » Needs review

Sorry - my mistake - I needed to pull your two latest commits. Working fine for me now. :-)

evamtinez’s picture

You're welcome @m.stenta and thank you for testing it.

  • m.stenta committed 3ea20c1 on 2.x
    #3236712: Renamed block plugin variable and use the renamed dashboard...
  • m.stenta committed 62562de on 2.x
    #3236712: Added new plugin block key to dashboard pane.
    
  • m.stenta committed 9e75989 on 2.x
    Issue #3236712 by evamtinez, m.stenta: Allow render custom blocks in the...
  • m.stenta committed af786a9 on 2.x
    #3236712: Added functionality to render custom blocks in dashboard.
    
  • m.stenta committed ddefa1e on 2.x
    #3236712: Rename new dashboard pane key.
    
m.stenta’s picture

Status: Needs review » Fixed

I talked this over with @paul121 and we decided to just use your approach for ALL block handling @evamtinez. In other words: instead of separate block and block_plugin options, we will ONLY have block, but it will expect a block plugin ID, and will use the code you provided.

I've added a commit that makes this change after yours, and adapted our existing dashboard blocks to take this approach.

One disadvantage of doing this is that it's no longer possible to include blocks that are created via the UI. But our thought is that this would really only be useful if you could also place them in the dashboard via the UI as well, with something like Layout Builder. So I created a follow-up issue to discuss that: #3238637: Use layout builder for farmOS dashboard

Status: Fixed » Closed (fixed)

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