You are here

trait ValidationConstraintMatchTrait in Varbase Media 9.0.x

Same name and namespace in other branches
  1. 8.7 modules/entity_browser_generic_embed/src/ValidationConstraintMatchTrait.php \Drupal\entity_browser_generic_embed\ValidationConstraintMatchTrait
  2. 8.5 modules/entity_browser_generic_embed/src/ValidationConstraintMatchTrait.php \Drupal\entity_browser_generic_embed\ValidationConstraintMatchTrait
  3. 8.6 modules/entity_browser_generic_embed/src/ValidationConstraintMatchTrait.php \Drupal\entity_browser_generic_embed\ValidationConstraintMatchTrait

Implements InputMatchInterface for media types that use an embed code or URL.

Hierarchy

2 files declare their use of ValidationConstraintMatchTrait
VarbaseMediaInstagram.php in modules/varbase_media_instagram/src/Plugin/media/Source/VarbaseMediaInstagram.php
VarbaseMediaTwitter.php in modules/varbase_media_twitter/src/Plugin/media/Source/VarbaseMediaTwitter.php

File

modules/entity_browser_generic_embed/src/ValidationConstraintMatchTrait.php, line 11

Namespace

Drupal\entity_browser_generic_embed
View source
trait ValidationConstraintMatchTrait {

  /**
   * Returns the typed data manager.
   *
   * @return \Drupal\Core\TypedData\TypedDataManagerInterface
   *   The typed data manager.
   */
  private function typedDataManager() {
    return @($this->typedDataManager ?: \Drupal::typedDataManager());
  }

  /**
   * Implements InputMatchInterface::appliesTo().
   */
  public function appliesTo($value, MediaTypeInterface $media_type) {
    $plugin_definition = $this
      ->getPluginDefinition();
    $definition = $this
      ->typedDataManager()
      ->createDataDefinition('string')
      ->addConstraint($plugin_definition['input_match']['constraint']);
    $data = StringData::createInstance($definition);
    $data
      ->setValue($value);
    return $data
      ->validate()
      ->count() === 0;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ValidationConstraintMatchTrait::appliesTo public function Implements InputMatchInterface::appliesTo().
ValidationConstraintMatchTrait::typedDataManager private function Returns the typed data manager.