function DirectoryWithMetadataDiscovery::findProvider

Same name in this branch
  1. 11.x core/modules/sdc/src/Plugin/Discovery/DirectoryWithMetadataDiscovery.php \Drupal\sdc\Plugin\Discovery\DirectoryWithMetadataDiscovery::findProvider()
Same name in other branches
  1. 10 core/modules/sdc/src/Plugin/Discovery/DirectoryWithMetadataDiscovery.php \Drupal\sdc\Plugin\Discovery\DirectoryWithMetadataDiscovery::findProvider()
  2. 10 core/lib/Drupal/Core/Plugin/Discovery/DirectoryWithMetadataDiscovery.php \Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery::findProvider()

Finds the provider of the discovered file.

The approach here is suboptimal because the provider is actually set in the plugin definition after the getIdentifier is called. So we either do this, or we forego the base class.

Parameters

string $file: The discovered file.

array $provider_paths: The associative array of the path to the provider.

Return value

string The provider

1 call to DirectoryWithMetadataDiscovery::findProvider()
DirectoryWithMetadataDiscovery::getIdentifier in core/lib/Drupal/Core/Plugin/Discovery/DirectoryWithMetadataDiscovery.php
The IDs can collide in two different scenarios:

File

core/lib/Drupal/Core/Plugin/Discovery/DirectoryWithMetadataDiscovery.php, line 88

Class

DirectoryWithMetadataDiscovery
Does the actual finding of the directories with metadata files.

Namespace

Drupal\Core\Plugin\Discovery

Code

private function findProvider(string $file, array $provider_paths) : string {
    $parts = explode(DIRECTORY_SEPARATOR, $file);
    array_pop($parts);
    if (empty($parts)) {
        return '';
    }
    $provider = $provider_paths[implode(DIRECTORY_SEPARATOR, $parts)] ?? '';
    return empty($provider) ? $this->findProvider(implode(DIRECTORY_SEPARATOR, $parts), $provider_paths) : $provider;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.