Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Created July 12, 2019 20:25
Show Gist options
  • Save rpayanm/c80350ae1989494385f08e114fc3d3ec to your computer and use it in GitHub Desktop.
Save rpayanm/c80350ae1989494385f08e114fc3d3ec to your computer and use it in GitHub Desktop.
<?php
class ExmapleForm extends FormBase {
// ...
/**
* Mantenemos cuantas veces el form es puesto en la página.
*
* @var int
*/
protected static $instanceId;
/**
* {@inheritdoc}
*/
public function getFormId() {
if (empty(self::$instanceId)) {
self::$instanceId = 1;
}
else {
self::$instanceId++;
}
return 'MODULENAME_EXAMPLE_' . self::$instanceId;
}
/**
* Ajax callback.
*/
public function ajaxSubmitForm(array $form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$instance_id = self::$instanceId;
// ...
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment