You are here

protected function Twitter::matchRegexp in Media entity Twitter 8

Runs preg_match on embed code/URL.

Parameters

MediaInterface $media: Media object.

Return value

array|bool Array of preg matches or FALSE if no match.

See also

preg_match()

1 call to Twitter::matchRegexp()
Twitter::getField in src/Plugin/MediaEntity/Type/Twitter.php
Gets a media-related field/value.

File

src/Plugin/MediaEntity/Type/Twitter.php, line 433

Class

Twitter
Provides media type plugin for Twitter.

Namespace

Drupal\media_entity_twitter\Plugin\MediaEntity\Type

Code

protected function matchRegexp(MediaInterface $media) {
  $matches = array();
  if (isset($this->configuration['source_field'])) {
    $source_field = $this->configuration['source_field'];
    if ($media
      ->hasField($source_field)) {
      $property_name = $media->{$source_field}
        ->first()
        ->mainPropertyName();
      foreach (static::$validationRegexp as $pattern => $key) {
        if (preg_match($pattern, $media->{$source_field}->{$property_name}, $matches)) {
          return $matches;
        }
      }
    }
  }
  return FALSE;
}