diff --git a/planet4-gutenberg-blocks.php b/planet4-gutenberg-blocks.php index e7df653f2..3e41c44d3 100644 --- a/planet4-gutenberg-blocks.php +++ b/planet4-gutenberg-blocks.php @@ -385,6 +385,32 @@ function ( $posts, $query ) { ); } +add_filter( 'timber/twig', 'p4_blocks_en_forms_twig_filters' ); + +/** + * Adds functionality to Twig. + * + * @param \Twig\Environment $twig The Twig environment. + * @return \Twig\Environment + */ +function p4_blocks_en_forms_twig_filters( $twig ) { + // Adding functions as filters. + $twig->addFilter( + new Twig_SimpleFilter( + 'object_to_array_plugin', + function ( $std_class_object ) { + $response = []; + foreach ( $std_class_object as $key => $value ) { + $response[ $key ] = $value; + } + return $response; + } + ) + ); + + return $twig; +} + /* ========================== L O A D P L U G I N diff --git a/templates/blocks/enform/enform_post.twig b/templates/blocks/enform/enform_post.twig index 71414cb27..51be2e48f 100644 --- a/templates/blocks/enform/enform_post.twig +++ b/templates/blocks/enform/enform_post.twig @@ -57,10 +57,10 @@ {% endif %} {% if 'GEN' == field.en_type %} {% set i = 0 %} - {% for locale, question_options in field.question_options|object_to_array %} + {% for locale, question_options in field.question_options|object_to_array_plugin %} {% if ( locale == field.selected_locale ) %} {% for question_option in question_options %} - {% set question_option = question_option|object_to_array %} + {% set question_option = question_option|object_to_array_plugin %}