ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Alexander Killing <killing@leifos.de> Extended GPL, see docs/LICENSE */
4 
6 
12 use \ILIAS\UI\Implementation\Render\Template;
14 
16 {
20  public function render(Component\Component $component, RendererInterface $default_renderer)
21  {
22  $this->checkComponent($component);
23 
27  return $this->renderDropdown($component, $default_renderer);
28  }
29 
30  protected function renderDropdown(Dropdown $component, RendererInterface $default_renderer)
31  {
32 
33  // get template
34  $tpl_name = "tpl.standard.html";
35  $tpl = $this->getTemplate($tpl_name, true, true);
36 
37  // render items
38  $items = $component->getItems();
39  if (is_array($items) && count($items) == 0) {
40  return "";
41  }
42  $this->renderItems($items, $tpl, $default_renderer);
43 
44  // render trigger button
45  $label = $component->getLabel();
46  if ($label !== null) {
47  $tpl->setVariable("LABEL", $component->getLabel());
48  } else {
49  $tpl->setVariable("LABEL", "");
50  }
51 
52  // ensure that a) a separate aria label may be provided and
53  // b) that an empty label and empty aria-label will use the "actions" fallback
54  if ($component->getLabel() == "" || $component->getAriaLabel() != "") {
55  $aria_label = ($component->getAriaLabel() != "")
56  ? $component->getAriaLabel()
57  : $this->txt("actions");
58  $tpl->setCurrentBlock("aria_label");
59  $tpl->setVariable("ARIA_LABEL", $aria_label);
60  $tpl->parseCurrentBlock();
61  }
62 
63  $this->maybeRenderId($component, $tpl, "with_id", "ID");
64 
65  return $tpl->get();
66  }
67 
68  protected function renderItems(array $items, Template $tpl, RendererInterface $default_renderer)
69  {
70  foreach ($items as $item) {
71  $tpl->setCurrentBlock("item");
72  $tpl->setVariable("ITEM", $default_renderer->render($item));
73  $tpl->parseCurrentBlock();
74  }
75  }
76 
77 
78  protected function maybeRenderId(JavaScriptBindable $component, Template $tpl, $block, $template_var)
79  {
80  $id = $this->bindJavaScript($component);
81  if ($id !== null) {
82  $tpl->setCurrentBlock($block);
83  $tpl->setVariable($template_var, $id);
84  $tpl->parseCurrentBlock();
85  }
86  }
87 
91  public function registerResources(ResourceRegistry $registry)
92  {
93  parent::registerResources($registry);
94  $registry->register('./src/UI/templates/js/Dropdown/dropdown.js');
95  }
96 
100  protected function getComponentInterfaceName()
101  {
102  return array(Component\Dropdown\Standard::class
103  );
104  }
105 }
Registry for resources required by rendered output like Javascript or CSS.
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.null
Definition: Renderer.php:91
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
renderDropdown(Dropdown $component, RendererInterface $default_renderer)
Definition: Renderer.php:30
maybeRenderId(JavaScriptBindable $component, Template $tpl, $block, $template_var)
Definition: Renderer.php:78
setCurrentBlock($name)
Set the block to work on.
parseCurrentBlock()
Parse the block that is currently worked on.
setVariable($name, $value)
Set a variable in the current block.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
renderItems(array $items, Template $tpl, RendererInterface $default_renderer)
Definition: Renderer.php:68
This implements commonalities between different types of Dropdowns.
Definition: Dropdown.php:16
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.