public function SandboxForm::buildForm in oEmbed 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ SandboxForm.php, line 33
Class
Namespace
Drupal\oembed\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['url'] = array(
'#type' => 'textfield',
'#title' => $this
->t('URL'),
'#description' => $this
->t('URL to request from oEmbed provider'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Submit'),
);
if ($form_state
->hasValue('embed')) {
$renderer = \Drupal::service('renderer');
$form['response'] = array(
'#type' => 'container',
);
$form['response']['display']['oembed'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('oEmbed'),
);
$markup = $renderer
->render($form_state
->getValue([
'display',
'oembed',
]));
$form['response']['display']['oembed'][] = array(
'#markup' => Markup::create($markup),
);
$form['response']['display']['oembed'][] = array(
'#prefix' => '<pre>',
'#markup' => SafeMarkup::checkPlain($markup),
'#suffix' => '</pre>',
);
$form['response']['display']['oembed_thumbnail'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('oEmbed Thumbnail'),
);
$markup = $renderer
->render($form_state
->getValue([
'display',
'oembed_thumbnail',
]));
$form['response']['display']['oembed_thumbnail'][] = array(
'#markup' => $markup,
);
$form['response']['display']['oembed_thumbnail'][] = array(
'#prefix' => '<pre>',
'#markup' => SafeMarkup::checkPlain($markup),
'#suffix' => '</pre>',
);
$form['response']['details'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Details'),
);
$form['response']['details']['data'] = array(
'#prefix' => '<pre>',
'#markup' => $form_state
->getValue('embed'),
'#suffix' => '</pre>',
);
}
return $form;
}