Grido@master
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Grido
    • Components
      • Actions
      • Columns
      • Filters
    • DataSources
    • PropertyAccessors
    • Translations

Classes

  • Grido\Translations\FileTranslator
 1 <?php
 2 
 3 /**
 4  * This file is part of the Grido (https://github.com/o5/grido)
 5  *
 6  * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
 7  *
 8  * For the full copyright and license information, please view
 9  * the file LICENSE.md that was distributed with this source code.
10  */
11 
12 namespace Grido\Components\Columns;
13 
14 /**
15  * Link column.
16  *
17  * @package     Grido
18  * @subpackage  Components\Columns
19  * @author      Petr Bugyík
20  */
21 class Link extends Text
22 {
23     /**
24      * @param mixed $value
25      * @return \Nette\Utils\Html
26      */
27     protected function formatValue($value)
28     {
29         return $this->getAnchor($value);
30     }
31 
32     /**
33      * @param string $value
34      * @return string
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      * @param string $value
47      * @return string
48      */
49     protected function formatText($value)
50     {
51         return preg_replace('~^https?://~i', '', $value);
52     }
53 
54     /**
55      * @param mixed $value
56      * @return \Nette\Utils\Html
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 
Grido@master API documentation generated by ApiGen