15
15
use Drupal \Core \Ajax \SetDialogTitleCommand ;
16
16
use Drupal \Core \Entity \EntityInterface ;
17
17
use Drupal \Core \Entity \EntityTypeManagerInterface ;
18
+ use Drupal \Core \Extension \ModuleHandlerInterface ;
18
19
use Drupal \Core \Form \FormBase ;
19
20
use Drupal \Core \Form \FormBuilderInterface ;
20
21
use Drupal \Core \Form \FormStateInterface ;
@@ -56,6 +57,13 @@ class EntityEmbedDialog extends FormBase {
56
57
*/
57
58
protected $ eventDispatcher ;
58
59
60
+ /**
61
+ * The module handler.
62
+ *
63
+ * @var \Drupal\Core\Extension\ModuleHandlerInterface
64
+ */
65
+ protected $ moduleHandler ;
66
+
59
67
/**
60
68
* The entity browser.
61
69
*
@@ -79,12 +87,15 @@ class EntityEmbedDialog extends FormBase {
79
87
* The entity type manager service.
80
88
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
81
89
* Event dispatcher service.
90
+ * @param \Drupal\Core\Extension\ModuleHandlerInterface
91
+ * The module handler.
82
92
*/
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 ) {
84
94
$ this ->setDisplayPluginManager ($ plugin_manager );
85
95
$ this ->formBuilder = $ form_builder ;
86
96
$ this ->entityTypeManager = $ entity_type_manager ;
87
97
$ this ->eventDispatcher = $ event_dispatcher ;
98
+ $ this ->moduleHandler = $ module_handler ;
88
99
}
89
100
90
101
/**
@@ -95,7 +106,8 @@ public static function create(ContainerInterface $container) {
95
106
$ container ->get ('plugin.manager.entity_embed.display ' ),
96
107
$ container ->get ('form_builder ' ),
97
108
$ container ->get ('entity_type.manager ' ),
98
- $ container ->get ('event_dispatcher ' )
109
+ $ container ->get ('event_dispatcher ' ),
110
+ $ container ->get ('module_handler ' )
99
111
);
100
112
}
101
113
@@ -361,6 +373,40 @@ public function buildEmbedStep(array $form, FormStateInterface $form_state) {
361
373
'#title ' => $ this ->t ('Selected entity ' ),
362
374
'#markup ' => $ entity_label ,
363
375
);
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
+
364
410
$ form ['attributes ' ]['data-entity-type ' ] = array (
365
411
'#type ' => 'hidden ' ,
366
412
'#value ' => $ entity_element ['data-entity-type ' ],
0 commit comments