0

I am using Drupal 8.7.3 and Webform 8.x-5.2.

I created a custom composite field in a multistep webform by extending WebformCompositeBase. My users select a subject in an earlier step. In this step I want to take the key of the user selection and request data based on this key.

class OtherExpectationsComposite extends WebformCompositeBase {
    public static function getCompositeElements(array $element) {
        return [
            'depending_content' => [
                '#markup' => 'content depending on earlier selections'
            ]
        ];
    }
}

How can I load the data insert to the form by the user in the earlier steps? $element doesn't contain anything helpful.

2
  • The currently available APIs don't support this level of conditional logic. – jrockowitz Jul 3 '19 at 18:13
  • Ohh what a pitty. That's why I can't find a nice solution. :( – Melanie Kuhles Jul 3 '19 at 20:12
0

Finally I used the good old session.

My solution:

//mymodule.module
function mymodule_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
    $session = \Drupal::request()->getSession();
    $session->set('value_from_earlier_step', $form_state->get('value_from_earlier_step'));
}

//\src\Element\ExampleComposite.php
class ExampleComposite extends WebformCompositeBase {
    public static function getCompositeElements(array $element) {
        $session = \Drupal::request()->getSession();
        $expectations = $session->get('value_from_earlier_step');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.