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,
41 if ($phase == 'install' && \Drupal::moduleHandler()->moduleExists('media')) {
42 $version = explode('.', \Drupal::VERSION);
43 if ($version[1] >= 4) {
44 $requirements['media_module_incompatibility'] = [
45 'title' => t('Media Entity'),
46 'value' => t('The Media Entity module is not compatible with media in core.'),
47 'description' => t('The 1.x branch of Media Entity cannot be used in conjunction with the media module in core. Please check the 2.x branch for an upgrade path.'),
48 'severity' => REQUIREMENT_ERROR,
57 * Implements hook_install().
59 function media_entity_install() {
60 $source = drupal_get_path('module', 'media_entity') . '/images/icons';
61 $destination = \Drupal::config('media_entity.settings')->get('icon_base');
62 media_entity_copy_icons($source, $destination);
66 * Remove "type" base field.
68 function media_entity_update_8001() {
69 $fields = \Drupal::database()->query('DESCRIBE {media_field_data}')->fetchCol();
70 if (in_array('type', $fields)) {
71 \Drupal::database()->update('media_field_data')
72 ->fields(['type' => NULL])
76 $manager = \Drupal::entityDefinitionUpdateManager();
77 if ($field = $manager->getFieldStorageDefinition('type', 'media')) {
78 $manager->uninstallFieldStorageDefinition($field);
83 * Ensure media entity status value (defaulting to 1).
85 function media_entity_update_8002() {
86 // Ensure status values in 'media_field_data' table.
87 if (\Drupal::database()->schema()->tableExists('media_field_data')) {
89 ->update('media_field_data')
90 ->fields(['status' => 1])
91 ->condition('status', NULL, 'IS NULL')
95 // Ensure status values in 'media_field_revision' table.
96 if (\Drupal::database()->schema()->tableExists('media_field_revision')) {
98 ->update('media_field_revision')
99 ->fields(['status' => 1])
100 ->condition('status', NULL, 'IS NULL')
105 drupal_flush_all_caches();
109 * Ensure Entity API is installed.
111 function media_entity_update_8003() {
112 if (!_media_entity_check_entity_version()) {
113 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.');