public function SandboxForm::validateForm in oEmbed 8
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ SandboxForm.php, line 93
Class
Namespace
Drupal\oembed\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Normalize input and look up
$url = $form_state
->getValue('url');
$embed = oembed_get_data($url);
if (!empty($embed)) {
$form_state
->setValue('embed', SafeMarkup::checkPlain(print_r($embed, TRUE)));
$form_state
->setValue([
'display',
'oembed',
], oembed_render_element('oembed', $url));
$form_state
->setValue([
'display',
'oembed_thumbnail',
], oembed_render_element('oembed_thumbnail', $url));
}
else {
$form_state
->setError($form['url'], $this
->t('%input is not valid oEmbed URL.', array(
'%input' => $form_state
->getValue('url'),
)));
}
}