ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
30 {
34  public function render(Component\Component $component, RendererInterface $default_renderer): string
35  {
36  if ($component instanceof State) {
37  return $this->renderState($component, $default_renderer);
38  }
39 
40  $this->cannotHandleComponent($component);
41  }
42 
43 
44  protected function renderState(State $component, RendererInterface $default_renderer): string
45  {
46  $tpl = $this->getTemplate('tpl.promptstate.html', true, true);
47  $tpl->setVariable('COMMAND', $component->getCommand());
48 
49  foreach ($component->getParameters() as $key => $value) {
50  $tpl->setCurrentBlock('param');
51  $tpl->setVariable('KEY', $key);
52  $tpl->setVariable('VALUE', $value);
53  $tpl->parseCurrentBlock();
54  }
55 
56  $content_component = $component->getContent();
57  if ($content_component === null) {
58  return $tpl->get();
59  }
60 
61  $tpl->setVariable('CONTENT', $default_renderer->render($content_component));
62  $tpl->setVariable('TITLE', $component->getTitle());
63 
64  $buttons = $component->getButtons();
65  if ($content_component instanceof \ILIAS\UI\Component\Input\Container\Form\Form) {
66  $submit_button = $this->getUIFactory()->button()->standard(
67  $content_component->getSubmitLabel() ?? $this->txt("save"),
68  $content_component->getSubmitSignal()
69  );
70  $buttons[] = $submit_button;
71  }
72 
73  $buttons[] = $this->getUIFactory()->button()
74  ->standard($this->txt('close_prompt'), '')
75  ->withOnLoadCode(
76  fn($id) => "$('#$id').on('click', (e)=> {
77  let promptId = e.target.closest('dialog').parentNode.id;
78  il.UI.prompt.get(promptId).close();
79  });"
80  );
81 
82  $tpl->setVariable('BUTTONS', $default_renderer->render($buttons));
83  return $tpl->get();
84  }
85 
86 }
renderState(State $component, RendererInterface $default_renderer)
Definition: Renderer.php:44
Interface Observer Contains several chained tasks and infos about them.
txt(string $id)
Get a text from the language file.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:34