You are here

function scald_update_providers in Scald: Media Management made easy 6

Determine if Scald Providers have been enabled or disabled and update the Scald Registries as necessary.

This function generates a list of all Drupal Modules which implement the scald_provider() hook. That list is compared against Scald Core's list of registered Providers and the Provider (un)registration functions are called in order to bring the two into sync. Necessarily, the Scald Configuration Object is rebuilt afterwards.

NOTE: Because there is no convenient way to fire a function upon the enabling of a new module, this function must masquerade as a form sumbission handler. It is nothing of the kind, however, and ignores the required arguments completely.

Parameters

$form: Ignored. Included for function definition parity.

$form_state: Ignored. Included for function definition parity.

Return value

Void.

1 call to scald_update_providers()
scald_enable in ./scald.install
Implementation of hook_enable().
1 string reference to 'scald_update_providers'
scald_form_system_modules_alter in ./scald.module
Implementation of hook_form_FORM_ID_alter().

File

./scald.module, line 418

Code

function scald_update_providers($form = NULL, &$form_state = NULL) {
  $registered_providers = variable_get('scald_providers', array());
  $current_implementers = module_implements('scald_provider');
  $to_register = array_diff($current_implementers, $registered_providers);
  foreach ($to_register as $module) {
    _scald_register_provider($module, module_invoke($module, 'scald_provider'));

    // _scald_register_provider checks the scald_config variable. Thus, we need
    // to rebuild it to give fresh informations to the next module that will be
    // registered.
    scald_config_rebuild();
  }
  $to_unregister = array_diff($registered_providers, $current_implementers);
  foreach ($to_unregister as $module) {
    _scald_unregister_provider($module);
  }

  // @@@TODO: Make the list dependent on successful registration.  Need a more sophistocated return value in _scald_register_provider() to accomplish this.
  variable_set('scald_providers', $current_implementers);
  scald_config_rebuild();
}