Skip to content
This repository was archived by the owner on Nov 16, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public function getForm(array &$original_form, FormStateInterface $form_state, a
return $form;
}

$bundles = $this->getTargetBundles($form_state);
try {
$entity = $this->helper->createFromInput($value);
$entity = $this->helper->createFromInput($value, $bundles);
}
catch (IndeterminateBundleException $e) {
return $form;
Expand Down Expand Up @@ -126,8 +127,10 @@ public function validate(array &$form, FormStateInterface $form_state) {
parent::validate($form, $form_state);

$value = $this->getInputValue($form_state);
$bundles = $this->getTargetBundles($form_state);

try {
$this->helper->getBundleFromInput($value);
$this->helper->getBundleFromInput($value, TRUE, $bundles);
}
catch (IndeterminateBundleException $e) {
$form_state->setError($form['widget'], $e->getMessage());
Expand Down Expand Up @@ -176,6 +179,24 @@ protected function getInputValue(FormStateInterface $form_state) {
return $form_state->getValue('input');
}

/**
* Returns an array of bundles from the entity browser's widget context.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state.
*
* @return array
* The target media bundles.
*/
protected function getTargetBundles(FormStateInterface $form_state) {
$bundles = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FileUpload class includes this exact code, in its getForm() method. Can that be changed to call this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phenaproxima ,

I think so. Will make that change when I get a second or two. Thanks.

$entity_browser_info = $form_state->get('entity_browser');
if (!empty($entity_browser_info['widget_context']['target_bundles'])) {
$bundles = $entity_browser_info['widget_context']['target_bundles'];
}
return $bundles;
}

/**
* {@inheritdoc}
*/
Expand Down