5 * Install, uninstall and update hooks for Media entity module.
9 * Checks if required version of the Entity API is installed.
12 * TRUE if dependency is met and FALSE if not.
14 function _media_entity_check_entity_version() {
15 if (\Drupal::moduleHandler()->moduleExists('entity')) {
16 $info = system_get_info('module', 'entity');
17 if (version_compare($info['version'], '8.x-1.0-alpha3') >= 0) {
26 * Implements hook_requirements().
28 function media_entity_requirements($phase) {
30 if ($phase == 'update' && !_media_entity_check_entity_version()) {
31 $requirements['entity'] = [
32 'title' => t('Media entity'),
33 'value' => t('Entity API missing'),
35 '<a href=":url">Entity API >= 8.x-1.0-alpha3</a> module is now a dependency and needs to be installed before running updates.',
36 [':url' => 'https://www.drupal.org/project/entity']
38 'severity' => REQUIREMENT_ERROR,
45 * Implements hook_install().
47 function media_entity_install() {
48 $source = drupal_get_path('module', 'media_entity') . '/images/icons';
49 $destination = \Drupal::config('media_entity.settings')->get('icon_base');
50 media_entity_copy_icons($source, $destination);
54 * Remove "type" base field.
56 function media_entity_update_8001() {
57 $fields = \Drupal::database()->query('DESCRIBE {media_field_data}')->fetchCol();
58 if (in_array('type', $fields)) {
59 \Drupal::database()->update('media_field_data')
60 ->fields(['type' => NULL])
64 $manager = \Drupal::entityDefinitionUpdateManager();
65 if ($field = $manager->getFieldStorageDefinition('type', 'media')) {
66 $manager->uninstallFieldStorageDefinition($field);
71 * Ensure media entity status value (defaulting to 1).
73 function media_entity_update_8002() {
74 // Ensure status values in 'media_field_data' table.
75 if (\Drupal::database()->schema()->tableExists('media_field_data')) {
77 ->update('media_field_data')
78 ->fields(['status' => 1])
79 ->condition('status', NULL, 'IS NULL')
83 // Ensure status values in 'media_field_revision' table.
84 if (\Drupal::database()->schema()->tableExists('media_field_revision')) {
86 ->update('media_field_revision')
87 ->fields(['status' => 1])
88 ->condition('status', NULL, 'IS NULL')
93 drupal_flush_all_caches();
97 * Ensure Entity API is installed.
99 function media_entity_update_8003() {
100 if (!_media_entity_check_entity_version()) {
101 throw new \Drupal\Core\Utility\UpdateException('Entity API >= 8.x-1.0-alpha3 (drupal.org/project/entity) module is now a dependency and needs to be installed before running updates.');