EmbedCode.php in Lightning Media 8
File
src/Plugin/EntityBrowser/Widget/EmbedCode.php
View source
<?php
namespace Drupal\lightning_media\Plugin\EntityBrowser\Widget;
use Drupal\Core\Form\FormStateInterface;
class EmbedCode extends EntityFormProxy {
public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
$form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
$form['input'] = [
'#type' => 'textarea',
'#placeholder' => $this
->t('Enter a URL...'),
'#attributes' => [
'class' => [
'keyup-change',
],
],
'#ajax' => [
'event' => 'change',
'wrapper' => 'entity',
'method' => 'html',
'callback' => [
static::class,
'ajax',
],
],
];
return $form;
}
public function validate(array &$form, FormStateInterface $form_state) {
$value = trim($this
->getInputValue($form_state));
if ($value) {
parent::validate($form, $form_state);
}
else {
$form_state
->setError($form['widget'], $this
->t('You must enter a URL or embed code.'));
}
}
}
Classes
Name |
Description |
EmbedCode |
An Entity Browser widget for creating media entities from embed codes. |