1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Grido\Components\Columns;
13
14 15 16 17 18 19 20
21 class Link extends Text
22 {
23 24 25 26
27 protected function formatValue($value)
28 {
29 return $this->getAnchor($value);
30 }
31
32 33 34 35
36 protected function formatHref($value)
37 {
38 if (!preg_match('~^\w+://~i', $value)) {
39 $value = "http://" . $value;
40 }
41
42 return $value;
43 }
44
45 46 47 48
49 protected function formatText($value)
50 {
51 return preg_replace('~^https?://~i', '', $value);
52 }
53
54 55 56 57
58 protected function getAnchor($value)
59 {
60 $truncate = $this->truncate;
61 $this->truncate = NULL;
62
63 $value = parent::formatValue($value);
64 $href = $this->formatHref($value);
65 $text = $this->formatText($value);
66
67 $anchor = \Nette\Utils\Html::el('a')
68 ->setHref($href)
69 ->setText($text)
70 ->setTarget('_blank')
71 ->setRel('noreferrer');
72
73 if ($truncate) {
74 $anchor->setText($truncate($text))
75 ->setTitle($value);
76 }
77
78 return $anchor;
79 }
80 }
81