protected function EntityFormProxy::getCurrentEntity in Lightning Media 8.3
Same name and namespace in other branches
- 8.4 src/Plugin/EntityBrowser/Widget/EntityFormProxy.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\EntityFormProxy::getCurrentEntity()
Returns a media entity created from the current input, if possible.
Parameters
\Drupal\Core\Form\FormStateInterface $form_state: The current form state.
Return value
\Drupal\media\MediaInterface A media entity created from the current input value, if there is one, or NULL if no media entity can be created.
2 calls to EntityFormProxy::getCurrentEntity()
- EntityFormProxy::getForm in src/
Plugin/ EntityBrowser/ Widget/ EntityFormProxy.php - FileUpload::validate in src/
Plugin/ EntityBrowser/ Widget/ FileUpload.php
File
- src/
Plugin/ EntityBrowser/ Widget/ EntityFormProxy.php, line 95
Class
- EntityFormProxy
- Base class for EB widgets which wrap around an (inline) entity form.
Namespace
Drupal\lightning_media\Plugin\EntityBrowser\WidgetCode
protected function getCurrentEntity(FormStateInterface $form_state) {
$value = $this
->getCurrentValue($form_state);
$types = $this
->getCurrentTypes($form_state);
$type = $form_state
->getValue('bundle');
if (empty($type) && count($types) === 1) {
$type = reset($types)
->id();
}
if ($value && $type) {
return $this
->createMedia($value, $types[$type]);
}
return NULL;
}