ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
EmbeddedApplicationGSProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
35 use ILIAS\Data\URI;
37 
42 {
43  private const USE_METABAR = 1;
44  private const USE_MODE_INFO = 2;
45  private int $display_mode = self::USE_MODE_INFO;
46  public const EMBEDDED_APPLICATION = 'embedded_application';
48 
49  public function __construct(Container $dic)
50  {
51  parent::__construct($dic);
52  global $DIC;
53  $this->signal_generator = $DIC["ui.signal_generator"];
54  }
55 
57  {
58  return $this->context_collection->repository();
59  }
60 
61 
62  public function getPageBuilderDecorator(CalledContexts $screen_context_stack): ?PageBuilderModification
63  {
64  if ($this->display_mode !== self::USE_MODE_INFO) {
65  return null;
66  }
67  if (!$screen_context_stack->current()->getAdditionalData()->exists(self::EMBEDDED_APPLICATION)) {
68  return null;
69  }
70  $embedded_application = $screen_context_stack->current()->getAdditionalData()->get(
71  self::EMBEDDED_APPLICATION
72  );
73  if (!$embedded_application instanceof EmbeddedApplication) {
74  return null;
75  }
76 
77  return $this->factory->page()->withHighPriority()->withModification(
78  function (PagePartProvider $p) use ($embedded_application): Page {
79  $uif = $this->dic->ui()->factory();
80  $builder = new StandardPageBuilder();
81  $page_part_provider = new EmbeddedApplicationPagePartProvider(
82  $p,
83  $embedded_application
84  );
85 
86  $back_to = $this->dic->ctrl()->getLinkTargetByClass(
87  \ilWOPIEmbeddedApplicationGUI::class,
89  );
90  $back_to = new URI(rtrim(ILIAS_HTTP_PATH, '/') . '/' . ltrim($back_to, './'));
92  $page = $builder->build($page_part_provider);
93  if (!$embedded_application->isInline()) {
94  $page = $page->withModeInfo(
95  $uif->mainControls()->modeInfo(
96  $this->dic->language()->txt('close_wopi_editor'),
97  $back_to
98  )
99  );
100  $page = $page->withSystemInfos([]);
101  }
102 
103  return $page;
104  }
105  );
106  }
107 
108  public function getMetaBarModification(CalledContexts $screen_context_stack): ?MetaBarModification
109  {
110  if ($this->display_mode !== self::USE_METABAR) {
111  return null;
112  }
113  if (!$screen_context_stack->current()->getAdditionalData()->exists(self::EMBEDDED_APPLICATION)) {
114  return null;
115  }
116 
117  $embedded_application = $screen_context_stack->current()->getAdditionalData()->get(
118  self::EMBEDDED_APPLICATION
119  );
120  if (!$embedded_application instanceof EmbeddedApplication) {
121  return null;
122  }
123 
124  if ($embedded_application->isInline()) {
125  return null;
126  }
127 
128  $button = $this->buildCloseButton($embedded_application);
129 
130  return $this->factory->metabar()->withHighPriority()->withModification(
131  fn(?MetaBar $metabar): ?Metabar => $metabar !== null
132  ? $metabar->withClearedEntries()
133  ->withAdditionalEntry(
134  'close_editor',
135  $button
136  )
137  : null
138  );
139  }
140 
141  protected function buildCloseButton(
142  EmbeddedApplication $embedded_application,
143  ): Bulky {
144  $uif = $this->dic->ui()->factory();
145  $back_target = $embedded_application->getBackTarget();
146  $signal = $this->signal_generator->create();
147  $signal->addOption('target_url', (string) $back_target);
148  return $uif->button()->bulky(
149  $uif->symbol()->glyph()->close(),
150  $this->dic->language()->txt('close'),
151  (string) $back_target
152  )->withOnClick(
153  $signal
154  )->withOnLoadCode(fn($id): string => "il.WOPI.bindCloseSignal('$id', '{$signal->getId()}');");
155  }
156 }
withClearedEntries()
Get a copy of this MetaBar without any entries.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
global $DIC
Definition: shib_login.php:25
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
This describes a bulky button.
Definition: Bulky.php:28
This describes the Page.
Definition: Page.php:30
This describes the MetaBar.
Definition: MetaBar.php:32
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
$dic
Definition: ltiresult.php:33