public function MiconIcon::toJson in Micon 2.x
Same name and namespace in other branches
- 8 src/MiconIcon.php \Drupal\micon\MiconIcon::toJson()
Returns a trimmed, json encoded string of the rendered markup.
Return value
string A json encoded string.
Overrides MiconIconInterface::toJson
File
- src/
MiconIcon.php, line 184
Class
- MiconIcon
- Defines the Micon icon.
Namespace
Drupal\miconCode
public function toJson() {
$elements = $this
->toRenderable();
$elements['#attributes']['data-tags'] = $this
->getTags();
$markup = \Drupal::service('renderer')
->render($elements);
return json_encode(trim(preg_replace('/<!--(.|\\s)*?-->/', '', $markup
->jsonSerialize())));
}