ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TestComponent.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use \ILIAS\UI\Implementation\Render\ResourceRegistry;
9 use \ILIAS\UI\Renderer as DefaultRenderer;
10 use \ILIAS\UI\Component\Component;
12 
14 {
15  use ComponentHelper;
16 
17  public function __construct($text)
18  {
19  $this->text = $text;
20  }
21 }
22 
24 {
25  use ComponentHelper;
27 
28  public function __construct($text)
29  {
30  $this->text = $text;
31  }
32 }
33 
35 {
36  final public function __construct($ui_factory, $tpl_factory, $lng, $js_binding)
37  {
38  $this->ui_factory = $ui_factory;
39  $this->tpl_factory = $tpl_factory;
40  $this->lng = $lng;
41  $this->js_binding = $js_binding;
42  }
43 
44  public function render(Component $component, DefaultRenderer $default_renderer)
45  {
46  if ($component instanceof JSTestComponent) {
47  $text = $component->text;
48  $component = $component->withAdditionalOnLoadCode(function ($id) use ($text) {
49  return "id:$text.$id content:$text";
50  });
51  $this->bindOnloadCode($component);
52  }
53  return $component->text;
54  }
55 
56  public function registerResources(ResourceRegistry $registry)
57  {
58  $registry->register("test.js");
59  }
60 
61  private function bindOnloadCode(\ILIAS\UI\Component\JavaScriptBindable $component)
62  {
63  $binder = $component->getOnLoadCode();
64  $this->js_binding->addOnLoadCode($binder("id"));
65  }
66 }
Registry for resources required by rendered output like Javascript or CSS.
Class Factory.
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
Class BaseForm.
An entity that renders components to a string output.
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
if(!array_key_exists('StateId', $_REQUEST)) $id
trait ComponentHelper
Provides common functionality for component implementations.
A component is the most general form of an entity in the UI.
Definition: Component.php:13
__construct($ui_factory, $tpl_factory, $lng, $js_binding)
$lng
render(Component $component, DefaultRenderer $default_renderer)
bindOnloadCode(\ILIAS\UI\Component\JavaScriptBindable $component)
$text
Definition: errorreport.php:18
Interface to be extended by components that have the possibility to bind to Javascript.