From 5a3ac7137cc0d647ff88ef6cd42fe0c110486727 Mon Sep 17 00:00:00 2001 From: Diego Pino Navarro Date: Sun, 18 Apr 2021 22:21:20 -0400 Subject: [PATCH] Fixes missing URL value in. Hotspot info This requires https://github.com/esmero/format_strawberryfield/pull/152 --- src/Element/WebformPanoramaTour.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Element/WebformPanoramaTour.php b/src/Element/WebformPanoramaTour.php index 9fcdf93..71e9a4d 100644 --- a/src/Element/WebformPanoramaTour.php +++ b/src/Element/WebformPanoramaTour.php @@ -2,6 +2,7 @@ namespace Drupal\webform_strawberryfield\Element; +use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\FormElement; use Drupal\webform\Element\WebformCompositeBase; @@ -838,8 +839,17 @@ public static function addHotspotSubmit( $newid = Uuid::uuid4(); $hotspot->id = $element_name . '_' . $current_scene . '_' . $newid->toString(); if ($hotspot->type == 'url') { - $hotspot->URL = $hotspot->url; - $hotspot->type = 'info'; + $externalURL = $form_state->getValue( + [$element_name, 'hotspots_temp', 'url'] + ); + if (UrlHelper::isValid(trim($externalURL), TRUE)) { + $hotspot->URL = $externalURL; + $hotspot->type = 'info'; + } + else { + $form_state->setRebuild(TRUE); + return; + } } if ($hotspot->type == 'ado') { $nodeid = $form_state->getValue( @@ -881,7 +891,6 @@ public static function addHotspotSubmit( $hotspot->text = $hotspot->text; $hotspot->type = 'info'; } - $existing_objects[] = (array) $hotspot; // @TODO make sure people don't add twice the same coordinates! @@ -892,7 +901,6 @@ public static function addHotspotSubmit( $form_state->set($all_scenes_key, $allscenes); $form_state->setValue([$element_name, 'allscenes'], json_encode($allscenes)); - } else { // Do we alert the user? Form needs to be restarted static::messenger()->addError(t('Something bad happened with the Tour builder, sadly you will have you restart your session.')); @@ -1014,7 +1022,7 @@ public static function deleteHotSpot(array &$form, FormStateInterface $form_stat } $form_state->set($all_scenes_key, $allscenes); - $form_state->setValue([$element_name, 'allscenes'],json_encode($allscenes)); + $form_state->setValue([$element_name, 'allscenes'], json_encode($allscenes)); } else {