You are here

protected function Twitter::matchRegexp in Media entity Twitter 8.2

Runs preg_match on embed code/URL.

Parameters

\Drupal\media\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::getMetadata in src/Plugin/media/Source/Twitter.php
Gets the value for a metadata attribute for a given media item.

File

src/Plugin/media/Source/Twitter.php, line 448

Class

Twitter
Twitter entity media source.

Namespace

Drupal\media_entity_twitter\Plugin\media\Source

Code

protected function matchRegexp(MediaInterface $media) {
  $matches = [];
  $source_field = $this
    ->getSourceFieldDefinition($media->bundle->entity)
    ->getName();
  if ($media
    ->hasField($source_field) && !$media
    ->get($source_field)
    ->isEmpty()) {
    $property_name = $media
      ->get($source_field)
      ->first()
      ->mainPropertyName();
    foreach (static::$validationRegexp as $pattern => $key) {
      if (preg_match($pattern, $media
        ->get($source_field)->{$property_name}, $matches)) {
        return $matches;
      }
    }
  }
  return FALSE;
}