You are here

function fz152_form_id_matches in FZ152 8

Same name and namespace in other branches
  1. 7 fz152.module \fz152_form_id_matches()

Check is provided form id is match any of patterns.

1 call to fz152_form_id_matches()
fz152_form_alter in ./fz152.module
Implements hook_form_alter().

File

./fz152.module, line 11
Main file for hooks and custom functions.

Code

function fz152_form_id_matches($form_id, $patterns) {

  // Replace new lines by "|" and wildcard by ".*".
  $to_replace = [
    '/(\\r\\n?|\\n)/',
    // newlines
    '/\\\\\\*/',
  ];
  $replacements = [
    '|',
    '.*',
  ];
  $patterns_quoted = preg_quote($patterns, '/');
  $pattern = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
  preg_match($pattern, $form_id, $matches);
  return $matches;
}