Commit 0d2abd62 authored by nicola85's avatar nicola85

Alter only the webform submission form

parent 49d16108
...@@ -5,16 +5,20 @@ use Drupal\Core\Form\FormStateInterface; ...@@ -5,16 +5,20 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\webform\Entity\Webform;
/** /**
* Implements hook_form_alter(). * Implements hook_form_alter().
*/ */
function bee_webform_form_alter(&$form, FormStateInterface $form_state, $form_id) { function bee_webform_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (isset($form['#webform_id'])) { if (isset($form['#webform_id'])) {
$webform = \Drupal\webform\Entity\Webform::load($form['#webform_id']); $webform = Webform::load($form['#webform_id']);
foreach ($webform->getElementsDecodedAndFlattened() as $element_id => $element) {
if ($element['#type'] == 'webform_bee_reservation_form') { if ($form['#form_id'] == 'webform_submission_' . $webform->id() . '_add_form') {
$form['actions']['submit']['#submit'][] = 'bee_webform_form_submit'; foreach ($webform->getElementsDecodedAndFlattened() as $element_id => $element) {
if ($element['#type'] == 'webform_bee_reservation_form') {
$form['actions']['submit']['#submit'][] = 'bee_webform_form_submit';
}
} }
} }
} }
...@@ -24,7 +28,7 @@ function bee_webform_form_alter(&$form, FormStateInterface $form_state, $form_id ...@@ -24,7 +28,7 @@ function bee_webform_form_alter(&$form, FormStateInterface $form_state, $form_id
* bee_webform submission handler. * bee_webform submission handler.
*/ */
function bee_webform_form_submit($form, FormStateInterface $form_state) { function bee_webform_form_submit($form, FormStateInterface $form_state) {
$webform = \Drupal\webform\Entity\Webform::load($form['#webform_id']); $webform = Webform::load($form['#webform_id']);
foreach ($webform->getElementsDecodedAndFlattened() as $element_id => $element) { foreach ($webform->getElementsDecodedAndFlattened() as $element_id => $element) {
if ($element['#type'] == 'webform_bee_reservation_form') { if ($element['#type'] == 'webform_bee_reservation_form') {
$bee_element_id = $element_id; $bee_element_id = $element_id;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment