You are here

public function ViewmodepagePattern::getPatternRegex in View Mode Page 3.2.x

Same name and namespace in other branches
  1. 8.3 src/Entity/ViewmodepagePattern.php \Drupal\view_mode_page\Entity\ViewmodepagePattern::getPatternRegex()
  2. 4.0.x src/Entity/ViewmodepagePattern.php \Drupal\view_mode_page\Entity\ViewmodepagePattern::getPatternRegex()

Set the pattern regex to use during path processing.

Return value

string Returns the pattern regex to use during path processing.

Overrides ViewmodepagePatternInterface::getPatternRegex

File

src/Entity/ViewmodepagePattern.php, line 196

Class

ViewmodepagePattern
Defines the Viewmodepage pattern entity.

Namespace

Drupal\view_mode_page\Entity

Code

public function getPatternRegex() {
  $pattern = $this
    ->getPattern();
  $pattern = preg_replace('!/+!', '/', $pattern);
  $pattern = trim($pattern, '/');
  $patternArray = explode('/', $pattern);
  $patternRegex = '!^';
  foreach ($patternArray as $patternPart) {
    if ($patternPart == '%') {
      $patternRegex .= '/(.*)';
    }
    else {
      $patternRegex .= '/' . preg_quote($patternPart, '!');
    }
  }
  $patternRegex .= '$!';
  return $patternRegex;
}