You are here

public function SpamspanTrait::callbackEmailAddressesWithOptions in SpamSpan filter 8

Same name and namespace in other branches
  1. 8.2 src/SpamspanTrait.php \Drupal\spamspan\SpamspanTrait::callbackEmailAddressesWithOptions()

Callback function for preg_replace_callback.

Replaces user@exampl.com[mycontact|Contact me].

Parameters

array $matches: The matches from preg_match.

$matches[0] - the entire matched string. $matches[1] - the local part of the email address. $matches[2] - the domain of the email address. $matches[3] - the options, i.e. the text between [] after the email address.

Return value

string The replaced text.

1 call to SpamspanTrait::callbackEmailAddressesWithOptions()
SpamspanTrait::replaceEmailAddressesWithOptions in src/SpamspanTrait.php

File

src/SpamspanTrait.php, line 149

Class

SpamspanTrait
Trait SpamspanTrait.

Namespace

Drupal\spamspan

Code

public function callbackEmailAddressesWithOptions(array $matches) {
  $vars = [];
  if (!empty($matches[3])) {
    $options = explode('|', $matches[3]);
    if (!empty($options[0])) {
      $custom_form_url = trim($options[0]);
      if (!empty($custom_form_url)) {
        $vars['custom_form_url'] = $custom_form_url;
      }
    }
    if (!empty($options[1])) {
      $custom_displaytext = trim($options[1]);
      if (!empty($custom_displaytext)) {
        $vars['custom_displaytext'] = $custom_displaytext;
      }
    }
  }
  return $this
    ->output($matches[1], $matches[2], '', [], $vars);
}