public function ProviderBase::processDefinition in Express 8
Processes the provider plugin definition upon discovery.
Parameters
array $definition: The provider plugin definition.
string $plugin_id: The plugin identifier.
Overrides ProviderInterface::processDefinition
File
- themes/
contrib/ bootstrap/ src/ Plugin/ Provider/ ProviderBase.php, line 137 - Contains \Drupal\bootstrap\Plugin\Provider\ProviderBase.
Class
- ProviderBase
- CDN provider base class.
Namespace
Drupal\bootstrap\Plugin\ProviderCode
public function processDefinition(array &$definition, $plugin_id) {
$provider_path = ProviderManager::FILE_PATH;
file_prepare_directory($provider_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// Process API data.
if ($api = $this
->getApi()) {
// Use manually imported API data, if it exists.
if (file_exists("{$provider_path}/{$plugin_id}.json") && ($imported_data = file_get_contents("{$provider_path}/{$plugin_id}.json"))) {
$definition['imported'] = TRUE;
$response = new Response(200, [], $imported_data);
}
else {
$client = \Drupal::httpClient();
$request = new Request('GET', $api);
try {
$response = $client
->send($request);
} catch (RequestException $e) {
$response = new Response(400);
}
}
$contents = $response
->getBody(TRUE)
->getContents();
$json = Json::decode($contents) ?: [];
$this
->processApi($json, $definition);
}
}