Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/GeneratedLink.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Core; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Component\Render\MarkupInterface; |
Chris@0 | 6 use Drupal\Component\Utility\Unicode; |
Chris@0 | 7 use Drupal\Core\Render\BubbleableMetadata; |
Chris@0 | 8 |
Chris@0 | 9 /** |
Chris@0 | 10 * Used to return generated links, along with associated cacheability metadata. |
Chris@0 | 11 * |
Chris@0 | 12 * Note: not to be confused with \Drupal\Core\Link, which is for passing around |
Chris@0 | 13 * ungenerated links (typically link text + route name + route parameters). |
Chris@0 | 14 */ |
Chris@0 | 15 class GeneratedLink extends BubbleableMetadata implements MarkupInterface, \Countable { |
Chris@0 | 16 |
Chris@0 | 17 /** |
Chris@0 | 18 * HTML tag to use when building the link. |
Chris@0 | 19 */ |
Chris@0 | 20 const TAG = 'a'; |
Chris@0 | 21 |
Chris@0 | 22 /** |
Chris@0 | 23 * The HTML string value containing a link. |
Chris@0 | 24 * |
Chris@0 | 25 * @var string |
Chris@0 | 26 */ |
Chris@0 | 27 protected $generatedLink = ''; |
Chris@0 | 28 |
Chris@0 | 29 /** |
Chris@0 | 30 * Gets the generated link. |
Chris@0 | 31 * |
Chris@0 | 32 * @return string |
Chris@0 | 33 */ |
Chris@0 | 34 public function getGeneratedLink() { |
Chris@12 | 35 return $this->generatedLink; |
Chris@0 | 36 } |
Chris@0 | 37 |
Chris@0 | 38 /** |
Chris@0 | 39 * Sets the generated link. |
Chris@0 | 40 * |
Chris@0 | 41 * @param string $generated_link |
Chris@0 | 42 * The generated link. |
Chris@0 | 43 * |
Chris@0 | 44 * @return $this |
Chris@0 | 45 */ |
Chris@0 | 46 public function setGeneratedLink($generated_link) { |
Chris@0 | 47 $this->generatedLink = $generated_link; |
Chris@0 | 48 return $this; |
Chris@0 | 49 } |
Chris@0 | 50 |
Chris@0 | 51 /** |
Chris@0 | 52 * {@inheritdoc} |
Chris@0 | 53 */ |
Chris@0 | 54 public function __toString() { |
Chris@0 | 55 return (string) $this->generatedLink; |
Chris@0 | 56 } |
Chris@0 | 57 |
Chris@0 | 58 /** |
Chris@0 | 59 * {@inheritdoc} |
Chris@0 | 60 */ |
Chris@0 | 61 public function jsonSerialize() { |
Chris@0 | 62 return $this->__toString(); |
Chris@0 | 63 } |
Chris@0 | 64 |
Chris@0 | 65 /** |
Chris@0 | 66 * {@inheritdoc} |
Chris@0 | 67 */ |
Chris@0 | 68 public function count() { |
Chris@0 | 69 return Unicode::strlen($this->__toString()); |
Chris@0 | 70 } |
Chris@0 | 71 |
Chris@0 | 72 } |