flag-commenthooks.patch 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. diff --git a/flag.module b/flag.module
  2. index 8dd6181..d67cc8a 100644
  3. --- a/flag.module
  4. +++ b/flag.module
  5. @@ -342,82 +342,82 @@ function flag_node_links_alter(array &$links, NodeInterface $entity, array &$con
  6. *
  7. * Handles the 'show_in_links' and 'show_as_field' flag options.
  8. */
  9. -function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  10. - // Don't show on previews.
  11. - if ($entity->isNew()) {
  12. - return;
  13. - }
  14. -
  15. - $build['#cache']['contexts'][] = 'user.permissions';
  16. -
  17. - if (empty($build['#cache']['tags'])) {
  18. - $build['#cache']['tags'] = [];
  19. - }
  20. -
  21. - // Get all possible flags for this entity type.
  22. - $flag_service = \Drupal::service('flag');
  23. - $flags = $flag_service->getAllFlags($entity->getEntityTypeID(), $entity->bundle());
  24. -
  25. - foreach ($flags as $flag) {
  26. - $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $flag->getCacheTags());
  27. -
  28. - // Do not display the flag if disabled.
  29. - if (!$flag->status()){
  30. - continue;
  31. - }
  32. -
  33. - $flag_type_plugin = $flag->getFlagTypePlugin();
  34. -
  35. - // Only add cache key if flag link is displayed.
  36. - if (!$flag_type_plugin->showAsField() || !$display->getComponent('flag_' . $flag->id())) {
  37. - continue;
  38. - }
  39. -
  40. - $build['flag_' . $flag->id()] = [
  41. - '#lazy_builder' => ['flag.link_builder:build', [
  42. - $entity->getEntityTypeId(),
  43. - $entity->id(),
  44. - $flag->id(),
  45. - ]],
  46. - '#create_placeholder' => TRUE,
  47. - ];
  48. - }
  49. -}
  50. +// function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  51. +// // Don't show on previews.
  52. +// if ($entity->isNew()) {
  53. +// return;
  54. +// }
  55. +//
  56. +// $build['#cache']['contexts'][] = 'user.permissions';
  57. +//
  58. +// if (empty($build['#cache']['tags'])) {
  59. +// $build['#cache']['tags'] = [];
  60. +// }
  61. +//
  62. +// // Get all possible flags for this entity type.
  63. +// $flag_service = \Drupal::service('flag');
  64. +// $flags = $flag_service->getAllFlags($entity->getEntityTypeID(), $entity->bundle());
  65. +//
  66. +// foreach ($flags as $flag) {
  67. +// $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $flag->getCacheTags());
  68. +//
  69. +// // Do not display the flag if disabled.
  70. +// if (!$flag->status()){
  71. +// continue;
  72. +// }
  73. +//
  74. +// $flag_type_plugin = $flag->getFlagTypePlugin();
  75. +//
  76. +// // Only add cache key if flag link is displayed.
  77. +// if (!$flag_type_plugin->showAsField() || !$display->getComponent('flag_' . $flag->id())) {
  78. +// continue;
  79. +// }
  80. +//
  81. +// $build['flag_' . $flag->id()] = [
  82. +// '#lazy_builder' => ['flag.link_builder:build', [
  83. +// $entity->getEntityTypeId(),
  84. +// $entity->id(),
  85. +// $flag->id(),
  86. +// ]],
  87. +// '#create_placeholder' => TRUE,
  88. +// ];
  89. +// }
  90. +// }
  91. /**
  92. * Implements hook_entity_build_defaults_alter().
  93. */
  94. -function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
  95. - /** @var \Drupal\flag\FlagService $flag_service */
  96. - $flag_service = \Drupal::service('flag');
  97. -
  98. - // Get all possible flags for this entity type.
  99. - $flags = $flag_service->getAllFlags($entity->getEntityTypeId(), $entity->bundle());
  100. -
  101. - $no_cache = FALSE;
  102. - foreach ($flags as $flag) {
  103. - $flag_type_plugin = $flag->getFlagTypePlugin();
  104. -
  105. - // Make sure we're dealing with an entity flag type.
  106. - if (!$flag_type_plugin instanceof EntityFlagType) {
  107. - continue;
  108. - }
  109. -
  110. - // Only add max-age to entity render array if contextual links flag
  111. - // display is enabled.
  112. - if (!$flag_type_plugin->showContextualLink()) {
  113. - continue;
  114. - }
  115. -
  116. - $no_cache = TRUE;
  117. - }
  118. -
  119. - if ($no_cache) {
  120. - $build['#cache']['max-age'] = 0;
  121. - }
  122. -
  123. - return $build;
  124. -}
  125. +// function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
  126. +// /** @var \Drupal\flag\FlagService $flag_service */
  127. +// $flag_service = \Drupal::service('flag');
  128. +//
  129. +// // Get all possible flags for this entity type.
  130. +// $flags = $flag_service->getAllFlags($entity->getEntityTypeId(), $entity->bundle());
  131. +//
  132. +// $no_cache = FALSE;
  133. +// foreach ($flags as $flag) {
  134. +// $flag_type_plugin = $flag->getFlagTypePlugin();
  135. +//
  136. +// // Make sure we're dealing with an entity flag type.
  137. +// if (!$flag_type_plugin instanceof EntityFlagType) {
  138. +// continue;
  139. +// }
  140. +//
  141. +// // Only add max-age to entity render array if contextual links flag
  142. +// // display is enabled.
  143. +// if (!$flag_type_plugin->showContextualLink()) {
  144. +// continue;
  145. +// }
  146. +//
  147. +// $no_cache = TRUE;
  148. +// }
  149. +//
  150. +// if ($no_cache) {
  151. +// $build['#cache']['max-age'] = 0;
  152. +// }
  153. +//
  154. +// return $build;
  155. +// }
  156. /**
  157. * Implements hook_entity_view_alter().
  158. @@ -425,41 +425,41 @@ function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity
  159. * Alters node contextual links placeholder id to contain flag metadata, so that
  160. * contextual links cache considers flags granularity.
  161. */
  162. -function flag_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  163. - $entity_type = $entity->getEntityTypeId();
  164. - if (isset($build['#contextual_links'][$entity_type])) {
  165. - /** @var \Drupal\flag\FlagService $flag_service */
  166. - $flag_service = \Drupal::service('flag');
  167. -
  168. - // Get all possible flags for this entity type.
  169. - $flags = $flag_service->getAllFlags($entity_type, $entity->bundle());
  170. -
  171. - foreach ($flags as $flag) {
  172. - $flag_type_plugin = $flag->getFlagTypePlugin();
  173. -
  174. - // Make sure we're dealing with an entity flag type.
  175. - if (!$flag_type_plugin instanceof EntityFlagType) {
  176. - continue;
  177. - }
  178. -
  179. - // Only apply metadata to contextual links if plugin is enabled
  180. - if (!$flag_type_plugin->showContextualLink()) {
  181. - continue;
  182. - }
  183. -
  184. - $action = 'flag';
  185. - if ($flag->isFlagged($entity)) {
  186. - $action = 'unflag';
  187. - }
  188. -
  189. - $flag_keys[] = $flag->id() . '-' . $action;
  190. - }
  191. -
  192. - if (!empty($flag_keys)) {
  193. - $build['#contextual_links'][$entity_type]['metadata']['flag_keys'] = implode(',', $flag_keys);
  194. - }
  195. - }
  196. -}
  197. +// function flag_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  198. +// $entity_type = $entity->getEntityTypeId();
  199. +// if (isset($build['#contextual_links'][$entity_type])) {
  200. +// /** @var \Drupal\flag\FlagService $flag_service */
  201. +// $flag_service = \Drupal::service('flag');
  202. +//
  203. +// // Get all possible flags for this entity type.
  204. +// $flags = $flag_service->getAllFlags($entity_type, $entity->bundle());
  205. +//
  206. +// foreach ($flags as $flag) {
  207. +// $flag_type_plugin = $flag->getFlagTypePlugin();
  208. +//
  209. +// // Make sure we're dealing with an entity flag type.
  210. +// if (!$flag_type_plugin instanceof EntityFlagType) {
  211. +// continue;
  212. +// }
  213. +//
  214. +// // Only apply metadata to contextual links if plugin is enabled
  215. +// if (!$flag_type_plugin->showContextualLink()) {
  216. +// continue;
  217. +// }
  218. +//
  219. +// $action = 'flag';
  220. +// if ($flag->isFlagged($entity)) {
  221. +// $action = 'unflag';
  222. +// }
  223. +//
  224. +// $flag_keys[] = $flag->id() . '-' . $action;
  225. +// }
  226. +//
  227. +// if (!empty($flag_keys)) {
  228. +// $build['#contextual_links'][$entity_type]['metadata']['flag_keys'] = implode(',', $flag_keys);
  229. +// }
  230. +// }
  231. +// }
  232. /**
  233. * Implements hook_contextual_links_alter().