You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
8.2KB

  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the thunder installation profile.
  5. */
  6. use Drupal\Component\Utility\NestedArray;
  7. use Drupal\update_helper\UpdateLogger;
  8. use Drupal\Core\Entity\EntityStorageException;
  9. use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
  10. /**
  11. * Update hook dependencies.
  12. *
  13. * Ensure that Thunder updates come last so entity schema updates and more
  14. * fundamental updates occur first.
  15. *
  16. * @return mixed
  17. * Returns list of update hook dependencies.
  18. */
  19. function thunder_update_dependencies() {
  20. $dependencies['thunder'] = [];
  21. // Ensure that all thunder hook_update_N functions are called after all other
  22. // update hooks.
  23. $list = [];
  24. $return = [];
  25. $updates = update_get_update_list();
  26. // List of thunder modules with hook_update_N() functions.
  27. $thunder_module_list = [
  28. 'thunder',
  29. 'thunder_article',
  30. 'thunder_liveblog',
  31. 'thunder_media',
  32. 'thunder_paragraphs',
  33. 'thunder_taxonomy',
  34. 'thunder_fia',
  35. 'thunder_riddle',
  36. ];
  37. foreach ($updates as $module => $info) {
  38. if (in_array($module, $thunder_module_list, TRUE)) {
  39. // Build a list of thunder modules with updates to run.
  40. $return[$module] = [];
  41. }
  42. else {
  43. // Build the list of all the update hooks for thunder updates to depend
  44. // on.
  45. $pending = array_keys($info['pending']);
  46. $list[$module] = array_pop($pending);
  47. }
  48. }
  49. // Add the dependencies to the thunder modules with updates to run.
  50. foreach ($return as $module => &$info) {
  51. $info[$updates[$module]['start']] = $list;
  52. }
  53. return NestedArray::mergeDeepArray([$return, $dependencies], TRUE);
  54. }
  55. /**
  56. * Helper function for direct use of update helper checklist service.
  57. *
  58. * @param string $update_id
  59. * Identifier of update in checklist.
  60. * @param bool $successful
  61. * The success or failure of update.
  62. * @param \Drupal\update_helper\UpdateLogger $updateLogger
  63. * Used update logger service in update hook.
  64. */
  65. function _thunder_mark_update_checklist($update_id, $successful, UpdateLogger $updateLogger) {
  66. try {
  67. /** @var \Drupal\update_helper_checklist\UpdateChecklist $update_checklist */
  68. $update_checklist = \Drupal::service('update_helper_checklist.update_checklist');
  69. if ($successful) {
  70. $update_checklist->markUpdatesSuccessful(['thunder' => [$update_id]]);
  71. }
  72. else {
  73. $update_checklist->markUpdatesFailed(['thunder' => [$update_id]]);
  74. }
  75. }
  76. catch (EntityStorageException $ee) {
  77. $updateLogger->warning(t('Unable to mark update in checklist.'));
  78. }
  79. catch (ServiceNotFoundException $se) {
  80. // If service is not available, we will just ignore it.
  81. }
  82. }
  83. /**
  84. * Implements hook_requirements().
  85. */
  86. function thunder_requirements($phase) {
  87. if ($phase !== 'update') {
  88. return [];
  89. }
  90. $requirements = [];
  91. $thunder_schema = drupal_get_installed_schema_version('thunder');
  92. if ($thunder_schema > 8000 && $thunder_schema < 8138) {
  93. $requirements['thunder'] = [
  94. 'title' => t('Thunder'),
  95. 'description' => t('You need to update to the latest version of Thunder 2 before switching to Thunder 3.'),
  96. 'severity' => REQUIREMENT_ERROR,
  97. ];
  98. }
  99. return $requirements;
  100. }
  101. /**
  102. * OBSOLETE - Add missing region key to field groups in form display settings.
  103. */
  104. function thunder_update_8301() {
  105. }
  106. /**
  107. * Change replace button to remove button on image paragraph form.
  108. */
  109. function thunder_update_8302() {
  110. /** @var \Drupal\update_helper\Updater $updateHelper */
  111. $updateHelper = \Drupal::service('update_helper.updater');
  112. // Execute configuration update definitions with logging of success.
  113. $updateHelper->executeUpdate('thunder', 'thunder_update_8302');
  114. // Output logged messages to related channel of update execution.
  115. return $updateHelper->logger()->output();
  116. }
  117. /**
  118. * Installs the autosave_form module.
  119. */
  120. function thunder_update_8303() {
  121. /** @var \Drupal\update_helper\Updater $updateHelper */
  122. $updateHelper = \Drupal::service('update_helper.updater');
  123. // Execute configuration update definitions with logging of success.
  124. $updateHelper->executeUpdate('thunder', 'thunder_update_8303');
  125. // Output logged messages to related channel of update execution.
  126. return $updateHelper->logger()->output();
  127. }
  128. /**
  129. * Installs the autofill module.
  130. */
  131. function thunder_update_8304() {
  132. /** @var \Drupal\update_helper\Updater $updateHelper */
  133. $updateHelper = \Drupal::service('update_helper.updater');
  134. // Execute configuration update definitions with logging of success.
  135. $updateHelper->executeUpdate('thunder', 'thunder_update_8304');
  136. // Output logged messages to related channel of update execution.
  137. return $updateHelper->logger()->output();
  138. }
  139. /**
  140. * Disable paragraphs drag & drop action button.
  141. */
  142. function thunder_update_8305() {
  143. /** @var \Drupal\update_helper\Updater $updateHelper */
  144. $updateHelper = \Drupal::service('update_helper.updater');
  145. // Execute configuration update definitions with logging of success.
  146. $updateHelper->executeUpdate('thunder', 'thunder_update_8305');
  147. // Output logged messages to related channel of update execution.
  148. return $updateHelper->logger()->output();
  149. }
  150. /**
  151. * Adjust order of paragraph types in add dialog to be consistent.
  152. */
  153. function thunder_update_8306() {
  154. /** @var \Drupal\update_helper\Updater $updateHelper */
  155. $updateHelper = \Drupal::service('update_helper.updater');
  156. // Execute configuration update definitions with logging of success.
  157. $updateHelper->executeUpdate('thunder', 'thunder_update_8306');
  158. // Output logged messages to related channel of update execution.
  159. return $updateHelper->logger()->output();
  160. }
  161. /**
  162. * Change entity browser widget in paragraphs integration.
  163. */
  164. function thunder_update_8307() {
  165. /** @var \Drupal\update_helper\Updater $updateHelper */
  166. $updateHelper = \Drupal::service('update_helper.updater');
  167. $configFactory = \Drupal::configFactory();
  168. // Modify paragraph form displays using inline_entity_form.
  169. $entityFormDisplayIds = Drupal::entityQuery('entity_form_display')
  170. ->condition('targetEntityType', 'paragraph')
  171. ->execute();
  172. try {
  173. $entityFormDisplayStorage = \Drupal::entityTypeManager()->getStorage('entity_form_display');
  174. foreach ($entityFormDisplayIds as $entityFormDisplayId) {
  175. /** @var \Drupal\Core\Entity\EntityDisplayBase $entityFormDisplay */
  176. $entityFormDisplay = $entityFormDisplayStorage->load($entityFormDisplayId);
  177. foreach ($entityFormDisplay->getComponents() as $name => $options) {
  178. // Modify only entity_browser_entity_reference fields with field widget
  179. // display 'inline_entity_form'.
  180. if ($options['type'] !== 'entity_browser_entity_reference' || $options['settings']['field_widget_display'] !== 'inline_entity_form') {
  181. continue;
  182. }
  183. unset($options['settings']['field_widget_display_settings']['form_mode']);
  184. $options['settings']['field_widget_display'] = 'rendered_entity';
  185. $options['settings']['field_widget_edit'] = TRUE;
  186. $options['settings']['field_widget_display_settings']['view_mode'] = 'thumbnail';
  187. $entityFormDisplay->setComponent($name, $options)->save();
  188. // These kind of fields cannot be required.
  189. $field_id = 'field.field.' . $entityFormDisplay->getTargetEntityTypeId() . '.' . $entityFormDisplay->get('bundle') . '.' . $name;
  190. $field = $configFactory->getEditable($field_id);
  191. $field->set('required', FALSE)->save();
  192. $updateHelper->logger()->info('Converted field_widget_display from inline_entity form to rendered_entity for field ' . $name . ' in the ' . $entityFormDisplay->get('bundle') . ' paragraph ');
  193. }
  194. }
  195. }
  196. catch (\Exception $e) {
  197. $updateHelper->logger()->error($e->getMessage());
  198. }
  199. // Output logged messages to related channel of update execution.
  200. return $updateHelper->logger()->output();
  201. }
  202. /**
  203. * Let paragraph preview image style use the focal point.
  204. */
  205. function thunder_update_8308() {
  206. /** @var \Drupal\update_helper\Updater $updateHelper */
  207. $updateHelper = \Drupal::service('update_helper.updater');
  208. // Execute configuration update definitions with logging of success.
  209. $updateHelper->executeUpdate('thunder', 'thunder_update_8308');
  210. // Output logged messages to related channel of update execution.
  211. return $updateHelper->logger()->output();
  212. }