Skip to content
Snippets Groups Projects
Commit 35d97139 authored by Eirik Morland's avatar Eirik Morland Committed by Eirik Morland
Browse files

Issue #3005051 by eiriksm: Bundle can be wrong if using standard image field

parent 1c1b4fad
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ namespace Drupal\image_canvas_editor_api\Plugin\Field\FieldWidget;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\ElementInfoManagerInterface;
......@@ -125,11 +126,12 @@ class ImageCanvasEditorWidget extends ImageWidget {
$inline_form = NestedArray::getValue($form, array_slice($element['#array_parents'], 0, 4));
$form_mode = $inline_form['#form_mode'];
}
$bundle = self::getBundle($element, $form_state);
$link = [
'#attached' => ['library' => ['core/drupal.ajax']],
'#type' => 'link',
'#url' => Url::fromRoute('image_canvas_editor_api.editor', [
'bundle' => $element['#bundle'],
'bundle' => $bundle,
'field_name' => $field_name,
'form_mode' => $form_mode,
'entity_type' => $element['#entity_type'],
......@@ -156,4 +158,20 @@ class ImageCanvasEditorWidget extends ImageWidget {
return $element;
}
/**
* Get the bundle from the element, somehow.
*/
public static function getBundle($element, FormStateInterface $form_state) {
$bundle = NULL;
if (isset($element['#bundle'])) {
return $element['#bundle'];
}
if ($form_object = $form_state->getFormObject()) {
if ($form_object instanceof ContentEntityForm) {
return $form_object->getEntity()->bundle();
}
}
return $bundle;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment