I am trying to come up with a solution to fix the D8 Link module to allow URLs like example.com (the most common use case, imho). I was thinking it would be simple enough to modify the submit value during a custom validate function; but regardless of what I set the value to it still validates on the original value.
In a form alter I have done this:
$form('field_linktest')('widget')(0)('#element_validate')() = '_fix_link_field_value';
and then in that validate function I set the url uri value:
function _fix_link_field_value(&$element, FormStateInterface $form_state, &$complete_form) {
$url = $form_state->getValue('field_linktest');
$url(0)('uri') = 'http://example.com';
$form_state->setValue('field_linktest', $url);
}
But I still get the error: Manually entered paths should start with one of the following characters: / ? #