Created
July 12, 2019 20:25
-
-
Save rpayanm/c80350ae1989494385f08e114fc3d3ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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