1515use Drupal \Core \Ajax \SetDialogTitleCommand ;
1616use Drupal \Core \Entity \EntityInterface ;
1717use Drupal \Core \Entity \EntityTypeManagerInterface ;
18+ use Drupal \Core \Extension \ModuleHandlerInterface ;
1819use Drupal \Core \Form \FormBase ;
1920use Drupal \Core \Form \FormBuilderInterface ;
2021use Drupal \Core \Form \FormStateInterface ;
@@ -56,6 +57,13 @@ class EntityEmbedDialog extends FormBase {
5657 */
5758 protected $ eventDispatcher ;
5859
60+ /**
61+ * The module handler.
62+ *
63+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
64+ */
65+ protected $ moduleHandler ;
66+
5967 /**
6068 * The entity browser.
6169 *
@@ -79,12 +87,15 @@ class EntityEmbedDialog extends FormBase {
7987 * The entity type manager service.
8088 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
8189 * Event dispatcher service.
90+ * @param \Drupal\Core\Extension\ModuleHandlerInterface
91+ * The module handler.
8292 */
83- public function __construct (EntityEmbedDisplayManager $ plugin_manager , FormBuilderInterface $ form_builder , EntityTypeManagerInterface $ entity_type_manager , EventDispatcherInterface $ event_dispatcher ) {
93+ public function __construct (EntityEmbedDisplayManager $ plugin_manager , FormBuilderInterface $ form_builder , EntityTypeManagerInterface $ entity_type_manager , EventDispatcherInterface $ event_dispatcher, ModuleHandlerInterface $ module_handler ) {
8494 $ this ->setDisplayPluginManager ($ plugin_manager );
8595 $ this ->formBuilder = $ form_builder ;
8696 $ this ->entityTypeManager = $ entity_type_manager ;
8797 $ this ->eventDispatcher = $ event_dispatcher ;
98+ $ this ->moduleHandler = $ module_handler ;
8899 }
89100
90101 /**
@@ -95,7 +106,8 @@ public static function create(ContainerInterface $container) {
95106 $ container ->get ('plugin.manager.entity_embed.display ' ),
96107 $ container ->get ('form_builder ' ),
97108 $ container ->get ('entity_type.manager ' ),
98- $ container ->get ('event_dispatcher ' )
109+ $ container ->get ('event_dispatcher ' ),
110+ $ container ->get ('module_handler ' )
99111 );
100112 }
101113
@@ -361,6 +373,40 @@ public function buildEmbedStep(array $form, FormStateInterface $form_state) {
361373 '#title ' => $ this ->t ('Selected entity ' ),
362374 '#markup ' => $ entity_label ,
363375 );
376+
377+ $ edit_url = $ entity ->urlInfo ('edit-form ' );
378+ $ form ['entity_edit ' ] = [
379+ '#type ' => 'link ' ,
380+ '#title ' => $ this ->t ('Edit ' ),
381+ '#url ' => $ edit_url ,
382+ '#attributes ' => [
383+ 'target ' => '_blank ' ,
384+ 'class ' => ['button ' ],
385+ ],
386+ ];
387+
388+ if ($ this ->moduleHandler ->moduleExists ('entity_browser ' )) {
389+ // Configuration entities have no form object so we provide a fallback
390+ // to a normal link styled like a button.
391+ try {
392+ $ edit_form = $ this ->entityManager ()->getFormObject ($ entity ->getEntityTypeId (), 'edit ' );
393+
394+ $ form ['entity_edit ' ] = [
395+ '#type ' => 'button ' ,
396+ '#executes_submit_callback ' => FALSE ,
397+ '#value ' => $ this ->t ('Edit ' ),
398+ '#ajax ' => [
399+ 'url ' => \Drupal \Core \Url::fromRoute (
400+ 'entity_browser.edit_form ' , [
401+ 'entity_type ' => $ entity ->getEntityTypeId (),
402+ 'entity ' => $ entity ->id (),
403+ ]
404+ )
405+ ],
406+ ];
407+ } catch (\Exception $ e ) {}
408+ }
409+
364410 $ form ['attributes ' ]['data-entity-type ' ] = array (
365411 '#type ' => 'hidden ' ,
366412 '#value ' => $ entity_element ['data-entity-type ' ],
0 commit comments