|
@@ -22,7 +22,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
* title = @Translation("URL Replace filter"),
|
|
|
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
|
|
|
* settings = {
|
|
|
- * "replacements" = ''
|
|
|
+ * "replacements" = ""
|
|
|
* }
|
|
|
* )
|
|
|
*/
|
|
@@ -31,11 +31,15 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
const SETTING_NAME = 'replacements';
|
|
|
|
|
|
/**
|
|
|
+ * The current_route_match service.
|
|
|
+ *
|
|
|
* @var \Drupal\Core\Routing\CurrentRouteMatch
|
|
|
*/
|
|
|
protected $currentRouteMatch;
|
|
|
|
|
|
/**
|
|
|
+ * The messenger service.
|
|
|
+ *
|
|
|
* @var \Drupal\Core\Messenger\MessengerInterface
|
|
|
*/
|
|
|
protected $messenger;
|
|
@@ -45,9 +49,9 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
*
|
|
|
* @param array $configuration
|
|
|
* The plugin configuration.
|
|
|
- * @param $plugin_id
|
|
|
+ * @param string $plugin_id
|
|
|
* The plugin id.
|
|
|
- * @param $plugin_definition
|
|
|
+ * @param array $plugin_definition
|
|
|
* The plugin definition.
|
|
|
* @param \Drupal\Core\Routing\CurrentRouteMatch $currentRouteMatch
|
|
|
* The current_route_match service.
|
|
@@ -57,7 +61,7 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
public function __construct(
|
|
|
array $configuration,
|
|
|
$plugin_id,
|
|
|
- $plugin_definition,
|
|
|
+ array $plugin_definition,
|
|
|
CurrentRouteMatch $currentRouteMatch,
|
|
|
MessengerInterface $messenger
|
|
|
) {
|
|
@@ -159,8 +163,13 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
return !(empty($setting['original']) && empty($setting['replacement']));
|
|
|
});
|
|
|
|
|
|
- $result = serialize($validSettings);
|
|
|
- $form_state->setValue(['filters', 'url_replace_filter', 'settings', self::SETTING_NAME], $result);
|
|
|
+ $result = serialize(array_values($validSettings));
|
|
|
+ $form_state->setValue([
|
|
|
+ 'filters',
|
|
|
+ 'url_replace_filter',
|
|
|
+ 'settings',
|
|
|
+ self::SETTING_NAME,
|
|
|
+ ], $result);
|
|
|
|
|
|
if (empty($validSettings)) {
|
|
|
$parameterName = 'filter_format';
|
|
@@ -170,7 +179,8 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
'@format' => $parameterValue->label(),
|
|
|
':edit' => Url::fromRoute('entity.filter_format.edit_form', [
|
|
|
$parameterName => $parameterValue->id(),
|
|
|
- ])->toString()]), MessengerInterface::TYPE_WARNING);
|
|
|
+ ])->toString(),
|
|
|
+ ]), MessengerInterface::TYPE_WARNING);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -209,7 +219,7 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
/**
|
|
|
* Filter the given text.
|
|
|
*/
|
|
|
- public function _url_replace_filter_process($text, $format) {
|
|
|
+ public function doProcess($text, $format) {
|
|
|
$settings = _url_replace_filter_get_settings($format);
|
|
|
foreach ($settings as $setting) {
|
|
|
if ($setting['original']) {
|
|
@@ -247,8 +257,8 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
* @return string
|
|
|
* A formatted string.
|
|
|
*/
|
|
|
- public static function processPHPCallback(array $matches) {
|
|
|
- return self::processPHP($matches[1]);
|
|
|
+ public static function processPhpCallback(array $matches) {
|
|
|
+ return self::processPhp($matches[1]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -302,7 +312,7 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
/**
|
|
|
* Helper function for processCode().
|
|
|
*/
|
|
|
- public static function processPHPInline($matches) {
|
|
|
+ public static function processPhpInline($matches) {
|
|
|
// Undo nl2br.
|
|
|
$text = str_replace('<br />', '', $matches[0]);
|
|
|
// Decode entities (the highlighter re-entifies) and highlight text.
|
|
@@ -315,7 +325,7 @@ class UrlReplaceFilter extends FilterBase implements ContainerFactoryPluginInter
|
|
|
/**
|
|
|
* Processes chunks of escaped PHP code into HTML.
|
|
|
*/
|
|
|
- public static function processPHP($text) {
|
|
|
+ public static function processPhp($text) {
|
|
|
// Note, pay attention to odd preg_replace-with-/e behaviour on slashes.
|
|
|
// Undo possible linebreak filter conversion.
|
|
|
$text = preg_replace('@</?(br|p)\s*/?>@', '', str_replace('\"', '"', $text));
|