ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
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 
27 
29 {
30  public const DEFAULT_ICON_NAME = 'default';
31  public const ICON_NAME_PATTERN = 'icon_%s.svg';
32 
36  public function render(Component\Component $component, RendererInterface $default_renderer): string
37  {
38  if (!$component instanceof Component\Symbol\Icon\Icon) {
39  $this->cannotHandleComponent($component);
40  }
41 
42  $tpl = $this->getTemplate("tpl.icon.html", true, true);
43 
44  $id = $this->bindJavaScript($component);
45 
46  if ($id !== null) {
47  $tpl->setCurrentBlock("with_id");
48  $tpl->setVariable("ID", $id);
49  $tpl->parseCurrentBlock();
50  }
51 
52  $tpl->setVariable("NAME", $this->convertSpecialCharacters($component->getName()));
53  $tpl->setVariable("SIZE", $component->getSize());
54 
55  $tpl = $this->renderLabel($component, $tpl);
56 
57  if ($component instanceof Component\Symbol\Icon\Standard) {
58  $imagepath = $this->getStandardIconPath($component);
59  } else {
60  $imagepath = $this->convertSpecialCharacters($component->getIconPath());
61  }
62 
63  $ab = $this->convertSpecialCharacters($component->getAbbreviation() ?? '');
64  if ($ab) {
65  $tpl->setVariable("ABBREVIATION", $ab);
66 
67  $abbreviation_tpl = $this->getTemplate("tpl.abbreviation.svg", true, true);
68  $abbreviation_tpl->setVariable("ABBREVIATION", $ab);
69  $abbreviation = $abbreviation_tpl->get() . '</svg>';
70 
71  $image = file_get_contents(__DIR__ . "/../../../../../../../../public/" . $imagepath);
72  $image = substr($image, strpos($image, '<svg '));
73  $image = trim(str_replace('</svg>', $abbreviation, $image));
74  $imagepath = "data:image/svg+xml;base64," . base64_encode($image);
75  }
76 
77  $tpl->setVariable("CUSTOMIMAGE", $imagepath);
78 
79  if ($component->isDisabled()) {
80  $tpl->touchBlock('disabled');
81  $tpl->touchBlock('aria_disabled');
82  }
83 
84  return $tpl->get();
85  }
86 
87  protected function renderLabel(Component\Component $component, Template $tpl): Template
88  {
89  $tpl->setVariable('LABEL', $this->convertSpecialCharacters($component->getLabel()));
90  return $tpl;
91  }
92 
93  protected function getStandardIconPath(Component\Symbol\Icon\Icon $icon): string
94  {
95  $name = $icon->getName();
96  $is_in_standard_icon_list = in_array($name, $icon->getAllStandardHandles());
97  $is_in_page_editor_icon_list = in_array($name, $icon->getAllStandardPageEditorHandles());
98  if (!$is_in_standard_icon_list && !$is_in_page_editor_icon_list) {
99  $name = self::DEFAULT_ICON_NAME;
100  }
101  $pattern = self::ICON_NAME_PATTERN;
102 
103  $icon_path_name = '';
104  $icon_name = sprintf($pattern, $name);
105  if ($is_in_page_editor_icon_list) {
106  $icon_path_name = 'page_editor/' . $icon_name;
107  } else {
108  $icon_path_name = 'standard/' . $icon_name;
109  }
110 
111  return $this->getImagePathResolver()->resolveImagePath($icon_path_name);
112  }
113 }
renderLabel(Component\Component $component, Template $tpl)
Definition: Renderer.php:87
setVariable(string $name, $value)
Set a variable in the current block.
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.
getStandardIconPath(Component\Symbol\Icon\Icon $icon)
Definition: Renderer.php:93
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:36
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.