Retrieve unique block ID or machine name in build() method of BlockBase class

Created on 26 July 2015, over 9 years ago
Updated 15 March 2023, almost 2 years ago

Is it possible to retrieve the unique block id or the machine name in the build() method of a block? When creating multiple instances of the same block definition, I can't manage to get a unique value per block from within the block methods (like for example the ID that gets appended to the machine name, or the machine name itself). I tried out all methods and properties of the BlockBase class, but no results.

Thanks in advance for any help on this.

πŸ’¬ Support request
Status

Active

Version

10.1 ✨

Component
BlockΒ  β†’

Last updated 5 days ago

Created by

πŸ‡§πŸ‡ͺBelgium fernly

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States devkinetic

    Moving this up to the next major version, in the meantime, the workaround in #10 does the trick. I will note that blocks need to be resaved before the new info is stored in the the configuration.

  • πŸ‡¨πŸ‡¦Canada _randy

    #10 seems to only work for non-Layout Builder instances. Otherwise the callback_object in layout builder does not have a getEntity() method and fails.

  • Status changed to Closed: works as designed 3 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    I see that there are two solutions offered here, in #10 and #15. So, I am closing this Support Request and asking that further discussion happen outside the core issue queue.

    The Drupal Core issue queue is not the ideal place for support requests (that option is mostly there for filing support issues for contributed modules and themes). There are several support options listed on our support page β†’ (Community > Support at the top of Drupal.org) and there is Drupal Slack β†’ . Drupal Slack and the Forums, which are our two main support mechanisms in the Drupal community.

    Cheers

Production build 0.71.5 2024