ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\MetaData\Copyright;
22 
27 
28 class Renderer implements RendererInterface
29 {
30  protected Factory $factory;
31 
32  public function __construct(
33  Factory $factory
34  ) {
35  $this->factory = $factory;
36  }
37 
41  public function toUIComponents(CopyrightDataInterface $copyright): array
42  {
43  $res = [];
44  $has_link = false;
45  if (!is_null($image = $this->buildIcon($copyright))) {
46  $res[] = $image;
47  }
48  if (!is_null($link = $this->buildLink($copyright))) {
49  $res[] = $link;
50  $has_link = true;
51  }
52  if ($copyright->fullName() && !$has_link) {
53  $res[] = $this->textInLegacy($copyright->fullName());
54  }
55  return $res;
56  }
57 
58  protected function buildIcon(CopyrightDataInterface $copyright): ?Icon
59  {
60  if (!$copyright->imageLink()) {
61  return null;
62  }
63  return $this->customIcon(
64  (string) $copyright->imageLink(),
65  $copyright->altText()
66  );
67  }
68 
69  protected function buildLink(CopyrightDataInterface $copyright): ?Link
70  {
71  if (!$copyright->link()) {
72  return null;
73  }
74  return $this->standardLink(
75  $copyright->fullName() !== '' ? $copyright->fullName() : (string) $copyright->link(),
76  (string) $copyright->link()
77  );
78  }
79 
80  protected function customIcon(string $src, string $alt): Icon
81  {
82  return $this->factory->symbol()->icon()->custom($src, $alt, Icon::MEDIUM);
83  }
84 
85  protected function standardLink(string $label, string $action): Link
86  {
87  return $this->factory->link()->standard($label, $action);
88  }
89 
90  protected function textInLegacy(string $text): Legacy
91  {
92  return $this->factory->legacy($text);
93  }
94 }
$res
Definition: ltiservices.php:69
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:28
buildIcon(CopyrightDataInterface $copyright)
Definition: Renderer.php:58
__construct(Factory $factory)
Definition: Renderer.php:32
buildLink(CopyrightDataInterface $copyright)
Definition: Renderer.php:69
customIcon(string $src, string $alt)
Definition: Renderer.php:80
standardLink(string $label, string $action)
Definition: Renderer.php:85
toUIComponents(CopyrightDataInterface $copyright)
Definition: Renderer.php:41