php - Drupal 8 Dynamic form ID -


i wrote module dynamically create blocks. in each block have form. problem want dynamic form id each form, in moduleblockform.php can define static 1 with

  public function getformid() {     return 'mymodule_block_form';   } 

but want this:

  public function getformid() {     return 'mymodule_block_form_' . $foo;   } 

is possible ?

thanks help

sorry: can't comment yet, i'll write comment answer

the problem see in julie pelletier's answer, rand not generate unique number, suggest define private static integer slug, append each formid , increment it.

example:

private static $slug = 0; 

and in __construct()

self::$slug = 0; 

and in getformid()

self::$slug += 1; return 'mymodule_block_form_' . self::$slug; 

you can combine last 2 lines in one, wrote readability.

hope helps.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -