function public function ProviderBase::processDefinition

8.x-3.x ProviderBase.php public ProviderBase::processDefinition(array &$definition, $plugin_id)

Overrides ProviderInterface::processDefinition

Deprecated

in 8.x-3.18, will be removed in a future release.

Class

ProviderBase
CDN Provider base class.

Namespace

Drupal\bootstrap\Plugin\Provider

Source src/Plugin/Provider/ProviderBase.php (line 639)

public function processDefinition(array &$definition, $plugin_id) {
  // Due to code recursion and the need to keep this code in place for BC
  // reasons, this deprecated message should only be logged and not shown.
  Bootstrap::deprecated(FALSE);

  // Process API data.
  if ($api = $this->getApi()) {
    $provider_path = ProviderManager::FILE_PATH;
    file_prepare_directory($provider_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);

    // 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;
      try {
        $json = Json::decode($imported_data);
      }
      catch (\Exception $e) {
        // Intentionally left blank.
      }
    }
    // Otherwise, attempt to request API data if the provider has specified
    // an "api" URL to use.
    else {
      $json = Bootstrap::request($api)->getData();
    }

    if (!isset($json)) {
      $json = [];
      $definition['error'] = TRUE;
    }

    $this->processApi($json, $definition);
  }
}