Skip to content
This repository was archived by the owner on Jan 5, 2018. It is now read-only.

Fix constraint validation, match regex against url-string not value #10

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ class VideoProviderMatchConstraintValidator extends ConstraintValidator {
*/
public function validate($value, Constraint $constraint) {
$regexes = $constraint->getRegularExpressionsOption();
if (empty($value)) {
$url = $value->getUrl()->toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link fields are not the only field types that are supported in media_entity_embeddable_video. This code assumes it is.

if (empty($url)) {
return;
}

$matches = [];
foreach ($regexes as $reqular_expr) {
if (preg_match($reqular_expr, $value->value, $item_matches)) {
if (preg_match($reqular_expr, $url, $item_matches)) {
$matches[] = $item_matches;
}
}
Expand Down