I have coded a plugin in my module which extends block base and generates labels for block in /admin/structure/block page under Place block. These block are being generated for different entities. The creation of block for different entities is dynamic and depend on configuration setting of module.I am facing two problem related to this:Firstly,suppose in the configuration form I have selected comment and user so label for these two entities are created in the Place block section but when I deselect comment then the label for comment remains still remains in block section.And when I clear the cache the label for comment is removed from Place block section.The code which I am using in build() function is:

public function build() {  
  return array(
    '#theme' => 'links__entity__module',
    '#links' => $this->linkBuilder->buildLinks($this->request->attributes->get($entity_type)),

What changes should I make so that configuration changes are immediately reflected in the /admin/structure/block page?

For the other problem I am facing I asked it over here:All instances of block are not getting removed. Thanks.

  • The question is still pretty confusing and hard to read. Asking different things in a single question is almost always a bad idea. You might not know, but I can tell you that they are completely different problems that require different solutions. So I recommend you open a separate question for the second part.
    – Berdir
    Jun 10, 2015 at 19:49
  • Made some small formatting improvements to make your code snippet better readable. I also suggest you chose a better question title, something like "Refresh block plugin derivates after making changes" or something like that, that focuses on the first question and actually is a question.
    – Berdir
    Jun 10, 2015 at 20:01

1 Answer 1


Answering the first part.

Do I read this correctly that you are saying that you are using block plugin derivates, one for each enabled entity type?

This has nothing to do with build()/displaying output in the block. That can't be solved with cache tags, you need to explicitly clear block plugin cache.

More often than not, D8 core has a similar or identical problem that it needs to solve, so what you should try to do is identify similar cases in Core and then try to find out how the problem was solved there.

In this case, it's custom block/block content entities. The list needs to be updated whenever a new one is created, the code you're looking for is in BlockContent::postSave():

// Invalidate the block cache to update custom block-based derivatives.

PS: You can find the solution for your second question in the same class, although the way it's implemented there is actually a bit wrong, that however doesn't matter for you, since you need to do it in a different way anyway. Feel free to open a new question to get a more detailed answer.

  • Thanks for the detailed answer. Do u think clearing block cache in submitForm() function is the best place to do so?Also I have updated my problem statement. Jun 11, 2015 at 6:59
  • You can put it in submit, but there's one problem with that. If your configuration changes directly and not through the form (drush, config deployment), then the necessary changes might not be invalidated. What you can do for that is a config save event, see Drupal\language\EventSubscriber\ConfigSubscriber for an example, also see language.services.yml for how that class is registered there.
    – Berdir
    Jun 11, 2015 at 9:34
  • Is it possible to have block with path like /block/{block} ? Actually I want to get block's object using this path and then calling \Drupal::routeMatch()->getParameter('block'). Thanks. Jun 14, 2015 at 22:57
  • Can u please help me with second part of question, link is here: drupal.stackexchange.com/questions/161539/… . Thanks. Jun 20, 2015 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.