Skip to content
This repository was archived by the owner on Jan 5, 2018. It is now read-only.

Commit b3f2e89

Browse files
committed
Issue #2513086 by JamesK: Right click option to edit entity: not reference a different entity, but *edit* the entity in a dialog
1 parent 607254d commit b3f2e89

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/Form/EntityEmbedDialog.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,40 @@ public function buildEmbedStep(array $form, FormStateInterface $form_state) {
361361
'#title' => $this->t('Selected entity'),
362362
'#markup' => $entity_label,
363363
);
364+
365+
$edit_url = $entity->urlInfo('edit-form');
366+
$form['entity_edit'] = [
367+
'#type' => 'link',
368+
'#title' => $this->t('Edit'),
369+
'#url' => $edit_url,
370+
'#attributes' => [
371+
'target' => '_blank',
372+
'class' => ['button'],
373+
],
374+
];
375+
376+
if ($this->moduleHandler()->moduleExists('entity_browser')) {
377+
// Configuration entities have no form object so we provide a fallback
378+
// to a normal link styled like a button.
379+
try {
380+
$edit_form = $this->entityManager()->getFormObject($entity->getEntityTypeId(), 'edit');
381+
382+
$form['entity_edit'] = [
383+
'#type' => 'button',
384+
'#executes_submit_callback' => FALSE,
385+
'#value' => $this->t('Edit'),
386+
'#ajax' => [
387+
'url' => \Drupal\Core\Url::fromRoute(
388+
'entity_browser.edit_form', [
389+
'entity_type' => $entity->getEntityTypeId(),
390+
'entity' => $entity->id(),
391+
]
392+
)
393+
],
394+
];
395+
} catch (\Exception $e) {}
396+
}
397+
364398
$form['attributes']['data-entity-type'] = array(
365399
'#type' => 'hidden',
366400
'#value' => $entity_element['data-entity-type'],

0 commit comments

Comments
 (0)