public function TestMappingSubscriber::mapTypesFromInput

Demonstrate mapping between external type and site schema type.

Parameters

\Drupal\rdf\MapTypesFromInputEvent $event: The mapping event.

File

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

Class

TestMappingSubscriber

Namespace

Drupal\rdf_test_mapping\EventSubscriber

Code

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]);
    }
  }
}