class TestMappingSubscriber

Hierarchy

Expanded class hierarchy of TestMappingSubscriber

1 file declares its use of TestMappingSubscriber
RdfMappingEventTest.php in drupal/core/modules/rdf/lib/Drupal/rdf/Tests/RdfMappingEventTest.php
Contains RdfMappingEventTest.
1 string reference to 'TestMappingSubscriber'
rdf_test_mapping.services.yml in drupal/core/modules/rdf/tests/rdf_test_mapping/rdf_test_mapping.services.yml
drupal/core/modules/rdf/tests/rdf_test_mapping/rdf_test_mapping.services.yml
1 service uses TestMappingSubscriber

File

drupal/core/modules/rdf/tests/rdf_test_mapping/lib/Drupal/rdf_test_mapping/EventSubscriber/TestMappingSubscriber.php, line 15
Contains TestMappingSubscriber.

Namespace

Drupal\rdf_test_mapping\EventSubscriber
View source
class TestMappingSubscriber implements EventSubscriberInterface {
  const STAGING_SITE_TYPE_URI = 'http://staging.com/entity_test_bundle';

  /**
   * Demonstrate mapping between external type and site schema type.
   *
   * @param \Drupal\rdf\MapTypesFromInputEvent $event
   *   The mapping event.
   */
  public function mapTypesFromInput($event) {
    $input_uris = $event
      ->getInputUris();
    $site_schema_types = $event
      ->getSiteSchemaTypes();

    // This mapping between an external type and a site schema type would be
    // managed by something in the implementing module, such as a database
    // table. For the test, manually map a fake external URI to the site schema
    // URI for the test entity.
    $schema = new SiteSchema(SiteSchema::CONTENT_DEPLOYMENT);
    $bundle_schema = $schema
      ->bundle('entity_test', 'entity_test');
    $site_schema_type = $bundle_schema
      ->getUri();
    $mapping = array(
      self::STAGING_SITE_TYPE_URI => $site_schema_type,
    );
    foreach ($input_uris as $input_uri) {

      // If the incoming URI is mapped in the mapping array, and the value of
      // that mapping is found in the cache of site schema types, then set the
      // site schema URI.
      if (isset($mapping[$input_uri]) && isset($site_schema_types[$mapping[$input_uri]])) {
        $event
          ->setSiteSchemaUri($mapping[$input_uri]);
      }
    }
  }

  /**
   * Implements EventSubscriberInterface::getSubscribedEvents().
   */
  static function getSubscribedEvents() {
    $events[RdfMappingEvents::MAP_TYPES_FROM_INPUT] = 'mapTypesFromInput';
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestMappingSubscriber::getSubscribedEvents static function Implements EventSubscriberInterface::getSubscribedEvents(). Overrides EventSubscriberInterface::getSubscribedEvents
TestMappingSubscriber::mapTypesFromInput public function Demonstrate mapping between external type and site schema type.
TestMappingSubscriber::STAGING_SITE_TYPE_URI constant