Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues/138--metadatadate-validation-error --> 1.0.0 #139

Open
wants to merge 1 commit into
base: 1.0.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Plugin/WebformElement/MetadataDateBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Drupal\webform\Plugin\WebformElementBase;
use Drupal\webform\Utility\WebformArrayHelper;
use Drupal\webform\Utility\WebformDateHelper;
use Drupal\webform\WebformSubmissionConditionsValidator;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform\WebformInterface;

Expand Down Expand Up @@ -268,6 +269,43 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
parent::validateConfigurationForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function getElementSelectorInputValue($selector, $trigger, array $element, WebformSubmissionInterface $webform_submission) {
$input_name = WebformSubmissionConditionsValidator::getSelectorInputName($selector);
$input_keys = WebformSubmissionConditionsValidator::getInputNameAsArray($input_name, NULL);
// Multi-value fields utilize input paths in the form 'webform_example_element_multiple[items][0][_item_]' => '{Test 01}',
// but ::getRawValue does not work with 'items' and '_item_' in the path. So we strip them out here.
$input_keys = array_diff($input_keys, ['items', '_item_']);
// After doing so, we expect the input keys to be in the form:
// ['webform field name', 'the composite element key'] OR ['webform field name', 'multiple-value delta', 'the composite element key']
// If neither case applies, return NULL;
if(!(count($input_keys) == 2 || count($input_keys) == 3)) {
return NULL;
}
else {
// Prepare options for ::getRawValue().
$options = [
'webform_key' => reset($input_keys),
'composite_key' => end($input_keys),
];
// Set delta for multiple value elements.
if(!empty($element['#multiple']) ) {
$options['delta'] = (count($input_keys) == 3 && is_numeric($input_keys[1])) ? $input_keys[1] : 0;
}

$input_value = $this->getRawValue($element, $webform_submission, $options);
// getRawValue can return an array, which \Drupal\webform\WebformSubmissionConditionsValidator::checkConditionTrigger
// tries to cast to a string and therefore generates a php array to string conversion warning.
// If the array is empty, we replace it with an empty string. Otherwise we let checkConditionTrigger complain.
if(is_array($input_value) && empty($input_value)) {
$input_value = "";
}
return $input_value;
}
}

/**
* Get the type of date/time element.
*
Expand Down