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
Branches
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ namespace Drupal\image_canvas_editor_api\Plugin\Field\FieldWidget; ...@@ -4,6 +4,7 @@ namespace Drupal\image_canvas_editor_api\Plugin\Field\FieldWidget;
use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\ElementInfoManagerInterface; use Drupal\Core\Render\ElementInfoManagerInterface;
...@@ -125,11 +126,12 @@ class ImageCanvasEditorWidget extends ImageWidget { ...@@ -125,11 +126,12 @@ class ImageCanvasEditorWidget extends ImageWidget {
$inline_form = NestedArray::getValue($form, array_slice($element['#array_parents'], 0, 4)); $inline_form = NestedArray::getValue($form, array_slice($element['#array_parents'], 0, 4));
$form_mode = $inline_form['#form_mode']; $form_mode = $inline_form['#form_mode'];
} }
$bundle = self::getBundle($element, $form_state);
$link = [ $link = [
'#attached' => ['library' => ['core/drupal.ajax']], '#attached' => ['library' => ['core/drupal.ajax']],
'#type' => 'link', '#type' => 'link',
'#url' => Url::fromRoute('image_canvas_editor_api.editor', [ '#url' => Url::fromRoute('image_canvas_editor_api.editor', [
'bundle' => $element['#bundle'], 'bundle' => $bundle,
'field_name' => $field_name, 'field_name' => $field_name,
'form_mode' => $form_mode, 'form_mode' => $form_mode,
'entity_type' => $element['#entity_type'], 'entity_type' => $element['#entity_type'],
...@@ -156,4 +158,20 @@ class ImageCanvasEditorWidget extends ImageWidget { ...@@ -156,4 +158,20 @@ class ImageCanvasEditorWidget extends ImageWidget {
return $element; 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