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

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -