- Issue created by @ErwinDeClerck
The ajax popup isn't working anymore as soon as the module is activated;
Error in log:
TypeError: Drupal\webform_remote_fields\Service\WebformRemoteFieldHelper::buildEndpointUrl(): Argument #1 ($endpoint) must be of type string, null given, called in /app/web/modules/contrib/webform_remote_fields/src/Traits/RemoteFieldBaseTrait.php on line 82 in Drupal\webform_remote_fields\Service\WebformRemoteFieldHelper->buildEndpointUrl() (line 156 of /app/web/modules/contrib/webform_remote_fields/src/Service/WebformRemoteFieldHelper.php).
Error shows as in screen shot
In line 82 WebformRemoteFieldHelper->buildEndpointUrl() needs a string and gets a NULL.
This value is build in line 54 $apiSettings = $wrHelperService->extractElementSettings($element, $formState);
in the method: extractElementSettings($element, $formState);
from Service/WebformRemoteFieldHelper, line 346
$apiEndpoint is set to NULL if $element['#api_endpoint'] not set;
LINE 348 $apiEndpoint = $element['#api_endpoint'] ?? NULL;
Setting this to
LINE 348 $apiEndpoint = $element['#api_endpoint'] ?? "";
Seems to work for me...
Drupal core 10.4.7
Webform 6.2.9
Webform Remote Fields 2.0.1
PHP 8.4.1
Replace NULL by "" in function extractElementSettings. line 348
/**
* Extract setting of the Webform remote field element.
*
* The order of array with the setting values.
* -> api_endpoint_add_query_parameter.
* -> api_endpoint.
* -> api_result_select_text.
* -> headers.
*
* @param array $element
* The webform element.
* @param \Drupal\Core\Form\FormStateInterface $formState
* An object of the form state.
*
* @return array
* Array with the key => value setting.
*/
public function extractElementSettings(array $element, FormStateInterface $formState): array {
$apiEndpointAddQueryParameter = $element['#api_endpoint_add_query_parameter'] ?? FALSE;
$apiEndpoint = $element['#api_endpoint'] ?? "";
$apiResultSelectValue = $element['#api_result_select_value'] ?? NULL;
$apiResultSelectText = $element['#api_result_select_text'] ?? NULL;
$apiNeedsHeader = $element['#needs_header'] ?? NULL;
$rootPropertyPath = $element['#root_property_path'] ?? NULL;
$custom_headers = [];
if ($apiNeedsHeader) {
$custom_headers = Yaml::parse($element['#headers']);
}
// As we have the support for get the property request value from,
// another webform field. We have to replace the tokens for
// #api_result_select_value setting at this point.
if (!empty($element['#api_result_select_value'])) {
$apiResultSelectValueToken = $this->token->replace(
$element['#api_result_select_value'],
['form_value' => $formState->getValues()],
);
if ($apiResultSelectValueToken) {
$apiResultSelectValue = $apiResultSelectValueToken;
}
}
return [
'api_endpoint_add_query_parameter' => $apiEndpointAddQueryParameter,
'api_endpoint' => $apiEndpoint,
'root_property_path' => $rootPropertyPath,
'api_result_select_value' => $apiResultSelectValue,
'api_result_select_text' => $apiResultSelectText,
'custom_headers' => $custom_headers,
'needs_header' => $apiNeedsHeader,
'api_round_result' => $element['#api_round_result'] ?? 0,
];
}
Active
2.0
Code