ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
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 
26 
32 {
36  public function render(Component\Component $component, RendererInterface $default_renderer): string
37  {
38  if (!$component instanceof Component\Legacy\Content) {
39  $this->cannotHandleComponent($component);
40  }
41 
42  $component = $this->registerSignals($component);
43  $this->bindJavaScript($component);
44  return $component->getContent();
45  }
46 
47  protected function registerSignals(Content $component): Component\JavaScriptBindable
48  {
49  $custom_signals = $component->getAllCustomSignals();
50 
51  return $component->withAdditionalOnLoadCode(function ($id) use ($custom_signals): string {
52  $code = "";
53  foreach ($custom_signals as $custom_signal) {
54  $signal_id = $custom_signal['signal'];
55  $signal_code = $custom_signal['js_code'];
56  $code .= "$(document).on('$signal_id', function(event, signalData) { $signal_code });";
57  }
58  return $code;
59  });
60  }
61 }
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:36
getAllCustomSignals()
Get a list of all registered signals and their custom JavaScript code.
Definition: Content.php:94
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.