MappyFilter.php in Mappy 8
File
src/Plugin/Filter/MappyFilter.php
View source
<?php
namespace Drupal\mappy\Plugin\Filter;
use Drupal\filter\Plugin\FilterBase;
use Drupal\filter\FilterProcessResult;
class MappyFilter extends FilterBase {
public function process($text, $langcode) {
$result = new FilterProcessResult($text);
$pattern = "/\\[mappy(\\:(.+))?( .+)?\\]/isU";
preg_match_all($pattern, $text, $matches);
foreach ($matches[0] as $ci => $token) {
preg_match_all("/(\\s)+(\\w+):(((\\s)*(\\w+))|(\\'(?:\\.|[^\\'\\\\])*\\'))/i", str_replace("'", "'", $token), $parameters);
$att = [];
foreach ($parameters['2'] as $key => $name) {
$att[$parameters['2'][$key]] = str_replace("'", "", $parameters['3'][$key]);
}
$service = $matches[2][$ci];
$attributes = "";
foreach ($att as $key => $value) {
$attributes .= " {$key}=\"{$value}\"";
}
$tag = "<{$service} {$attributes}></{$service}>";
$text = str_replace($token, $tag, $text);
}
$result
->setProcessedText($text);
return $result;
}
public function tips($long = FALSE) {
return $this
->t("Every [mappy:service address:'address'] token will be replaced with map.");
}
}
Classes
Name |
Description |
MappyFilter |
Provides a filter to display any HTML as plain text. |