class EmbedCode in Lightning Media 8.3
Same name and namespace in other branches
- 8.4 src/Plugin/EntityBrowser/Widget/EmbedCode.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EmbedCode
- 8 src/Plugin/EntityBrowser/Widget/EmbedCode.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EmbedCode
- 8.2 src/Plugin/EntityBrowser/Widget/EmbedCode.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EmbedCode
An Entity Browser widget for creating media entities from embed codes.
Plugin annotation
@EntityBrowserWidget(
id = "embed_code",
label = @Translation("Embed Code"),
description = @Translation("Allows creation of media entities from embed codes."),
)
Hierarchy
- class \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EntityFormProxy extends \Drupal\entity_browser\WidgetBase
- class \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EmbedCode
Expanded class hierarchy of EmbedCode
File
- src/
Plugin/ EntityBrowser/ Widget/ EmbedCode.php, line 16
Namespace
Drupal\lightning_media\Plugin\EntityBrowser\WidgetView source
class EmbedCode extends EntityFormProxy {
/**
* {@inheritdoc}
*/
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-form',
'method' => 'html',
'callback' => [
static::class,
'ajax',
],
],
// I don't know why, but this is needed to display error messages.
'#limit_validation_errors' => [
[
'input',
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
protected function getCurrentValue(FormStateInterface $form_state) {
$value = parent::getCurrentValue($form_state);
return trim($value);
}
/**
* {@inheritdoc}
*/
public function validate(array &$form, FormStateInterface $form_state) {
$value = $this
->getCurrentValue($form_state);
if ($value) {
parent::validate($form, $form_state);
}
elseif ($form_state
->isSubmitted()) {
$form_state
->setError($form['widget']['input'], $this
->t('You must enter a URL or embed code.'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EmbedCode:: |
protected | function |
Returns the current input value, if any. Overrides EntityFormProxy:: |
|
EmbedCode:: |
public | function |
Overrides EntityFormProxy:: |
|
EmbedCode:: |
public | function |
Overrides EntityFormProxy:: |
|
EntityFormProxy:: |
public | function | ||
EntityFormProxy:: |
public static | function | AJAX callback. Returns the rebuilt inline entity form. | |
EntityFormProxy:: |
protected | function | Creates a new, unsaved media entity from a source field value. | |
EntityFormProxy:: |
public | function | 1 | |
EntityFormProxy:: |
protected | function | Returns the media types which can be used by this widget. | |
EntityFormProxy:: |
protected | function | Returns a media entity created from the current input, if possible. | |
EntityFormProxy:: |
protected | function | Returns all media types that can apply to the current input. | |
EntityFormProxy:: |
protected | function | Returns media types which can accept a given value in their source field. | |
EntityFormProxy:: |
protected | function | Tests if a media type can be used by this widget. | 1 |
EntityFormProxy:: |
protected | function | 1 | |
EntityFormProxy:: |
public | function | 1 | |
EntityFormProxy:: |
public static | function | Submit callback for the Update button. |