From b3f2e89e8047fd126e79f5f8b9353ab748677a61 Mon Sep 17 00:00:00 2001 From: yannickoo Date: Mon, 13 Jun 2016 17:00:19 +0200 Subject: [PATCH] Issue #2513086 by JamesK: Right click option to edit entity: not reference a different entity, but *edit* the entity in a dialog --- src/Form/EntityEmbedDialog.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Form/EntityEmbedDialog.php b/src/Form/EntityEmbedDialog.php index 6ca9e795..049004a6 100644 --- a/src/Form/EntityEmbedDialog.php +++ b/src/Form/EntityEmbedDialog.php @@ -361,6 +361,40 @@ public function buildEmbedStep(array $form, FormStateInterface $form_state) { '#title' => $this->t('Selected entity'), '#markup' => $entity_label, ); + + $edit_url = $entity->urlInfo('edit-form'); + $form['entity_edit'] = [ + '#type' => 'link', + '#title' => $this->t('Edit'), + '#url' => $edit_url, + '#attributes' => [ + 'target' => '_blank', + 'class' => ['button'], + ], + ]; + + if ($this->moduleHandler()->moduleExists('entity_browser')) { + // Configuration entities have no form object so we provide a fallback + // to a normal link styled like a button. + try { + $edit_form = $this->entityManager()->getFormObject($entity->getEntityTypeId(), 'edit'); + + $form['entity_edit'] = [ + '#type' => 'button', + '#executes_submit_callback' => FALSE, + '#value' => $this->t('Edit'), + '#ajax' => [ + 'url' => \Drupal\Core\Url::fromRoute( + 'entity_browser.edit_form', [ + 'entity_type' => $entity->getEntityTypeId(), + 'entity' => $entity->id(), + ] + ) + ], + ]; + } catch (\Exception $e) {} + } + $form['attributes']['data-entity-type'] = array( '#type' => 'hidden', '#value' => $entity_element['data-entity-type'],