ILIAS  release_8 Revision v8.24
TestComponent.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24use ILIAS\UI\Implementation\Component\ComponentHelper;
25use ILIAS\UI\Renderer as DefaultRenderer;
32
33class TestComponent implements Component
34{
35 use ComponentHelper;
36
37 public string $text;
38
39 public function __construct(string $text)
40 {
41 $this->text = $text;
42 }
43}
44
46{
47 use ComponentHelper;
49
50 public string $text;
51
52 public function __construct(string $text)
53 {
54 $this->text = $text;
55 }
56}
57
59{
62 public \ilLanguage $lng;
64
66 {
67 $this->ui_factory = $ui_factory;
68 $this->tpl_factory = $tpl_factory;
69 $this->lng = $lng;
70 $this->js_binding = $js_binding;
71 }
72
73 public function render(Component $component, DefaultRenderer $default_renderer): string
74 {
75 if ($component instanceof JSTestComponent) {
76 $text = $component->text;
77 $component = $component->withAdditionalOnLoadCode(function ($id) use ($text) {
78 return "id:$text.$id content:$text";
79 });
80 $this->bindOnloadCode($component);
81 }
82 return $component->text;
83 }
84
85 public function registerResources(ResourceRegistry $registry): void
86 {
87 $registry->register("test.js");
88 }
89
90 private function bindOnloadCode(\ILIAS\UI\Component\JavaScriptBindable $component): void
91 {
92 $binder = $component->getOnLoadCode();
93 $this->js_binding->addOnLoadCode($binder("id"));
94 }
95}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
bindOnloadCode(\ILIAS\UI\Component\JavaScriptBindable $component)
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
__construct(Factory $ui_factory, TemplateFactory $tpl_factory, \ilLanguage $lng, JavaScriptBinding $js_binding)
render(Component $component, DefaultRenderer $default_renderer)
language handling
A component is the most general form of an entity in the UI.
Definition: Component.php:28
Interface to be extended by components that have the possibility to bind to Javascript.
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Provides methods to interface with javascript.
Registry for resources required by rendered output like Javascript or CSS.
register(string $name)
Add a dependency.
Interface for a factory that provides templates.
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.