19 declare(strict_types=1);
43 $tpl = $this->
getTemplate(
"tpl.image.html",
true,
true);
45 if (($sources = $component->getAdditionalHighResSources()) !== []) {
46 $component = $component->withAdditionalOnLoadCode(
47 fn(
string $id):
string =>
" 48 const imageElement = il.UI.image.getImageElement('$id'); 49 if (imageElement === null) { 50 throw new Error(`Image '$id' not found.`); 52 il.UI.image.loadHighResolutionSource( 54 {$this->getHighResSourceMapForJs($sources)} 61 if (!empty($component->getAction())) {
62 $tpl->touchBlock(
"action_begin");
64 if (is_string($component->getAction())) {
65 $tpl->setCurrentBlock(
"with_href");
66 $tpl->setVariable(
"HREF", $component->getAction());
67 $tpl->parseCurrentBlock();
70 if (is_array($component->getAction())) {
71 $tpl->setCurrentBlock(
"with_href");
72 $tpl->setVariable(
"HREF",
"#");
73 $tpl->parseCurrentBlock();
74 $tpl->setCurrentBlock(
"with_id");
75 $tpl->setVariable(
"ID",
$id);
76 $tpl->parseCurrentBlock();
80 if (!is_array($component->getAction()) &&
$id !==
null) {
81 $tpl->setVariable(
"IMG_ID",
" id='" .
$id .
"' ");
84 $tpl->setCurrentBlock($component->getType());
85 $tpl->setVariable(
"SOURCE", $component->getSource());
86 $tpl->setVariable(
"ALT", htmlspecialchars($component->getAlt()));
87 $tpl->parseCurrentBlock();
89 if (!empty($component->getAction())) {
90 $tpl->touchBlock(
"action_end");
101 parent::registerResources($registry);
102 $registry->
register(
'assets/js/image.min.js');
111 foreach ($resources as $min_width => $source) {
112 $map_entries .=
"[$min_width, '$source'],\n";
115 return "new Map([\n$map_entries])";
Registry for resources required by rendered output like Javascript or CSS.
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
getHighResSourceMapForJs(array $resources)
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.
register(string $name)
Add a dependency.
render(Component\Component $component, RendererInterface $default_renderer)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Base class for all component renderers.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.