function media_entity_requirements in Media entity 8.2
Same name and namespace in other branches
- 8 media_entity.install \media_entity_requirements()
Implements hook_requirements().
File
- ./
media_entity.install, line 174 - Install, uninstall and update hooks for Media entity module.
Code
function media_entity_requirements($phase) {
$requirements = [];
if ($phase == 'update' && !_media_entity_check_entity_version()) {
$requirements['entity'] = [
'title' => t('Media entity'),
'value' => t('Entity API missing'),
'description' => t('<a href=":url">Entity API >= 8.x-1.0-alpha3</a> module is now a dependency and needs to be installed before running updates.', [
':url' => 'https://www.drupal.org/project/entity',
]),
'severity' => _media_entity_check_entity_version(),
];
}
// Prevent this branch from being installed on new sites.
if ($phase == 'install') {
$requirements['media_entity_update_only'] = [
'title' => t('Media entity'),
'description' => t('This branch of Media Entity is intended for site upgrades only. Please use the 1.x branch or Drupal core >= 8.6.x if you are building a new site.'),
'severity' => REQUIREMENT_ERROR,
];
}
if ($phase == 'update') {
// Here we want to ensure that a series of requirements are met before
// letting the DB updates continue. However, the batch processing of
// hook_update_N() triggers this validation again during the update process.
// Because of that, we want to make sure that these requirements checks are
// only evaluated once, and we use a state variable for that.
if (!\Drupal::state()
->get('media_entity_core_upgrade_started')) {
$checks = \Drupal::service('media_entity.cli')
->validateDbUpdateRequirements();
foreach ($checks['errors'] as $key => $error_msg) {
$requirements['media_entity_upgrade_' . $key] = [
'title' => t('Media Entity'),
'value' => t('Please fix the error below and try again.'),
'description' => $error_msg,
'severity' => REQUIREMENT_ERROR,
];
}
}
}
if ($phase == 'runtime') {
if (drupal_get_installed_schema_version('media_entity') < 8201) {
$requirements['media_entity_update_status'] = [
'title' => t('Media Entity'),
'value' => t('DB updates for Media Entity pending.'),
'description' => t('After updating the Media Entity code, you need to run the <a href=":update">database update script</a> as soon as possible.', [
':update' => Url::fromRoute('system.db_update')
->toString(),
]),
'severity' => REQUIREMENT_WARNING,
];
}
else {
$requirements['media_entity_update_status'] = [
'title' => t('Media Entity'),
'value' => t('DB updates for Media Entity were run.'),
'description' => t('The Media Entity upgrade path was executed, you can now uninstall and remove the Media Entity module from the codebase.'),
'severity' => REQUIREMENT_OK,
];
}
}
return $requirements;
}