Problem/Motivation

I'm using a module which provides a block and specifically needs a unique ID in the render array.

Proposed resolution

Provide an ID based on the block plugin ID and a MD5 sum of the configuration variable.

CommentFileSizeAuthor
#9 3161956-9.patch500 bytesgchauhan
#3 3161956-1.patch453 bytestripox

Comments

tripox created an issue. See original summary.

chi’s picture

tripox’s picture

StatusFileSize
new453 bytes
tripox’s picture

Status: Active » Needs work
chi’s picture

+ '#id' => $id . '_' . md5(serialize($configuration)),

What is the point of having "md5(serialize($configuration))"? It does not make the ID unique.

tripox’s picture

What is the point of having "md5(serialize($configuration))"? It does not make the ID unique.

You're right, I was thinking it'd be unique. Do you have any suggestions?

If so, I will gladly update the patch. :)

chi’s picture

Here is how it is handled in 3.x branch
https://git.drupalcode.org/project/twig_tweak/-/blob/3.0.0-rc1/src/View/...

By default block plugin ID is used to create HTML ID, but users are free to pass custom ID through arguments.

gchauhan’s picture

Assigned: Unassigned » gchauhan
gchauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new500 bytes

Hi @Chi this is the patch as per your suggestions.
Thanks!

gchauhan’s picture

Assigned: gchauhan » Unassigned

  • Chi committed ccf146a on 8.x-2.x authored by gchauhan
    Issue #3161956 by tripox, gchauhan: No ID in render array for blocks
    
chi’s picture

Status: Needs review » Fixed

Thank you.

kaipipek’s picture

This change breaks our site. Error message in the log:

Error: Call to a member function getThirdPartySetting() on null funktiossa dexp_block_settings_preprocess_block() (line 258 in file /var/www/test/modules/drupalexp/modules/dexp_block_settings/dexp_block_settings.module)

The code in the mentioned dexp_block_settings.module file is:

if(($animate = $block->getThirdPartySetting('dexp_block_settings', 'animate')) && !$config->get('disable_animation')){
      $animate_delay = $block->getThirdPartySetting('dexp_block_settings', 'animate_delay', 0);
      $animate_duration = $block->getThirdPartySetting('dexp_block_settings', 'animate_duration', 1000);
			$variables['attributes']['data-aos'] = $animate;
      $variables['attributes']['data-aos-delay'] = $animate_delay;
      $variables['attributes']['data-aos-duration'] = $animate_duration;
			$variables['#attached']['library'][] = 'dexp_block_settings/animate';
      if($animate_duration > 3000 || $animate_duration % 50 != 0){
        $variables['attributes']['style'][] = "transition-duration:{$animate_duration}ms;";
      }
}
chi’s picture

kaipipek’s picture

Is there a fix planned or do you expect everyone else to fix their (often 3rd party) modules or stop using Twig Tweak?

chi’s picture

No any fixes planned yet.

kaipipek’s picture

For instance I personally have no idea how to fix this and I believe the affected module is not maintained anymore. I am suprised that you were not able to implement this new feature with backwards compatibility because there is no benefit from it for many old users.

chi’s picture

If this caused a BC break I may revert the commit. At any rate it needs clear steps to reproduce the issue (preferably with failing test).

kaipipek’s picture

I can give you the detailed error log or we can have a short Skype/Teams call if that helps?

chi’s picture

That's why issue queues exist on drupal.org. Just submit a new issue and provide exact steps to reproduce the problem on fresh Drupal installation.
https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett...

chi’s picture

@kaipipek #3174903: Error: Call to a member function getRegion() on null in hook_theme_suggestions_block_alter() has been just fixed. That may have resolved your issue too.

kaipipek’s picture

Yes, the issue has been resolved. Excellent, thanks!

Status: Fixed » Closed (fixed)

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