ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
29 
31 {
35  public function render(Component\Component $component, RendererInterface $default_renderer): string
36  {
37  $this->checkComponent($component);
38 
42  return $this->renderDropdown($component, $default_renderer);
43  }
44 
45  protected function renderDropdown(Dropdown $component, RendererInterface $default_renderer): string
46  {
47 
48  // get template
49  $tpl_name = "tpl.standard.html";
50  $tpl = $this->getTemplate($tpl_name, true, true);
51 
52  // render items
53  $items = $component->getItems();
54  if (is_array($items) && count($items) == 0) {
55  return "";
56  }
57  $this->renderItems($items, $tpl, $default_renderer);
58 
59  // render trigger button
60  $label = $component->getLabel();
61  if ($label !== null) {
62  $tpl->setVariable("LABEL", $component->getLabel());
63  } else {
64  $tpl->setVariable("LABEL", "");
65  }
66 
67  // ensure that a) a separate aria label may be provided and
68  // b) that an empty label and empty aria-label will use the "actions" fallback
69  if ($component->getLabel() == "" || $component->getAriaLabel() != "") {
70  $aria_label = ($component->getAriaLabel() != "")
71  ? $component->getAriaLabel()
72  : $this->txt("actions");
73  $tpl->setCurrentBlock("aria_label");
74  $tpl->setVariable("ARIA_LABEL", $aria_label);
75  $tpl->parseCurrentBlock();
76  }
77 
78  $this->renderId($component, $tpl);
79 
80  return $tpl->get();
81  }
82 
83  protected function renderItems(array $items, Template $tpl, RendererInterface $default_renderer): void
84  {
85  foreach ($items as $item) {
86  $tpl->setCurrentBlock("item");
87  $tpl->setVariable("ITEM", $default_renderer->render($item));
88  $tpl->parseCurrentBlock();
89  }
90  }
91 
92 
93  protected function renderId(
94  JavaScriptBindable $component,
96  ): void {
97  $id = $this->bindJavaScript($component);
98  if ($id === null) {
99  $id = $this->createId();
100  }
101  $tpl->setVariable("ID", $id);
102  $tpl->setVariable("ID_MENU", $id."_menu");
103 
104  }
105 
109  public function registerResources(ResourceRegistry $registry): void
110  {
111  parent::registerResources($registry);
112  $registry->register('./src/UI/templates/js/Dropdown/dropdown.js');
113  }
114 
118  protected function getComponentInterfaceName(): array
119  {
120  return array(Component\Dropdown\Standard::class);
121  }
122 }
Registry for resources required by rendered output like Javascript or CSS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Dropdown.php:21
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
Definition: Renderer.php:109
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
txt(string $id)
Get a text from the language file.
renderDropdown(Dropdown $component, RendererInterface $default_renderer)
Definition: Renderer.php:45
setCurrentBlock(string $name)
Set the block to work on.
setVariable(string $name, $value)
Set a variable in the current block.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
renderId(JavaScriptBindable $component, Template $tpl)
Definition: Renderer.php:93
register(string $name)
Add a dependency.
parseCurrentBlock()
Parse the block that is currently worked on.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
renderItems(array $items, Template $tpl, RendererInterface $default_renderer)
Definition: Renderer.php:83
This implements commonalities between different types of Dropdowns.
Definition: Dropdown.php:35
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.