123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- diff --git a/flag.module b/flag.module
- index 8dd6181..d67cc8a 100644
- --- a/flag.module
- +++ b/flag.module
- @@ -342,82 +342,82 @@ function flag_node_links_alter(array &$links, NodeInterface $entity, array &$con
- *
- * Handles the 'show_in_links' and 'show_as_field' flag options.
- */
- -function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
- - // Don't show on previews.
- - if ($entity->isNew()) {
- - return;
- - }
- -
- - $build['#cache']['contexts'][] = 'user.permissions';
- -
- - if (empty($build['#cache']['tags'])) {
- - $build['#cache']['tags'] = [];
- - }
- -
- - // Get all possible flags for this entity type.
- - $flag_service = \Drupal::service('flag');
- - $flags = $flag_service->getAllFlags($entity->getEntityTypeID(), $entity->bundle());
- -
- - foreach ($flags as $flag) {
- - $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $flag->getCacheTags());
- -
- - // Do not display the flag if disabled.
- - if (!$flag->status()){
- - continue;
- - }
- -
- - $flag_type_plugin = $flag->getFlagTypePlugin();
- -
- - // Only add cache key if flag link is displayed.
- - if (!$flag_type_plugin->showAsField() || !$display->getComponent('flag_' . $flag->id())) {
- - continue;
- - }
- -
- - $build['flag_' . $flag->id()] = [
- - '#lazy_builder' => ['flag.link_builder:build', [
- - $entity->getEntityTypeId(),
- - $entity->id(),
- - $flag->id(),
- - ]],
- - '#create_placeholder' => TRUE,
- - ];
- - }
- -}
- +// function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
- +// // Don't show on previews.
- +// if ($entity->isNew()) {
- +// return;
- +// }
- +//
- +// $build['#cache']['contexts'][] = 'user.permissions';
- +//
- +// if (empty($build['#cache']['tags'])) {
- +// $build['#cache']['tags'] = [];
- +// }
- +//
- +// // Get all possible flags for this entity type.
- +// $flag_service = \Drupal::service('flag');
- +// $flags = $flag_service->getAllFlags($entity->getEntityTypeID(), $entity->bundle());
- +//
- +// foreach ($flags as $flag) {
- +// $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $flag->getCacheTags());
- +//
- +// // Do not display the flag if disabled.
- +// if (!$flag->status()){
- +// continue;
- +// }
- +//
- +// $flag_type_plugin = $flag->getFlagTypePlugin();
- +//
- +// // Only add cache key if flag link is displayed.
- +// if (!$flag_type_plugin->showAsField() || !$display->getComponent('flag_' . $flag->id())) {
- +// continue;
- +// }
- +//
- +// $build['flag_' . $flag->id()] = [
- +// '#lazy_builder' => ['flag.link_builder:build', [
- +// $entity->getEntityTypeId(),
- +// $entity->id(),
- +// $flag->id(),
- +// ]],
- +// '#create_placeholder' => TRUE,
- +// ];
- +// }
- +// }
-
- /**
- * Implements hook_entity_build_defaults_alter().
- */
- -function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
- - /** @var \Drupal\flag\FlagService $flag_service */
- - $flag_service = \Drupal::service('flag');
- -
- - // Get all possible flags for this entity type.
- - $flags = $flag_service->getAllFlags($entity->getEntityTypeId(), $entity->bundle());
- -
- - $no_cache = FALSE;
- - foreach ($flags as $flag) {
- - $flag_type_plugin = $flag->getFlagTypePlugin();
- -
- - // Make sure we're dealing with an entity flag type.
- - if (!$flag_type_plugin instanceof EntityFlagType) {
- - continue;
- - }
- -
- - // Only add max-age to entity render array if contextual links flag
- - // display is enabled.
- - if (!$flag_type_plugin->showContextualLink()) {
- - continue;
- - }
- -
- - $no_cache = TRUE;
- - }
- -
- - if ($no_cache) {
- - $build['#cache']['max-age'] = 0;
- - }
- -
- - return $build;
- -}
- +// function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
- +// /** @var \Drupal\flag\FlagService $flag_service */
- +// $flag_service = \Drupal::service('flag');
- +//
- +// // Get all possible flags for this entity type.
- +// $flags = $flag_service->getAllFlags($entity->getEntityTypeId(), $entity->bundle());
- +//
- +// $no_cache = FALSE;
- +// foreach ($flags as $flag) {
- +// $flag_type_plugin = $flag->getFlagTypePlugin();
- +//
- +// // Make sure we're dealing with an entity flag type.
- +// if (!$flag_type_plugin instanceof EntityFlagType) {
- +// continue;
- +// }
- +//
- +// // Only add max-age to entity render array if contextual links flag
- +// // display is enabled.
- +// if (!$flag_type_plugin->showContextualLink()) {
- +// continue;
- +// }
- +//
- +// $no_cache = TRUE;
- +// }
- +//
- +// if ($no_cache) {
- +// $build['#cache']['max-age'] = 0;
- +// }
- +//
- +// return $build;
- +// }
-
- /**
- * Implements hook_entity_view_alter().
- @@ -425,41 +425,41 @@ function flag_entity_build_defaults_alter(array &$build, EntityInterface $entity
- * Alters node contextual links placeholder id to contain flag metadata, so that
- * contextual links cache considers flags granularity.
- */
- -function flag_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
- - $entity_type = $entity->getEntityTypeId();
- - if (isset($build['#contextual_links'][$entity_type])) {
- - /** @var \Drupal\flag\FlagService $flag_service */
- - $flag_service = \Drupal::service('flag');
- -
- - // Get all possible flags for this entity type.
- - $flags = $flag_service->getAllFlags($entity_type, $entity->bundle());
- -
- - foreach ($flags as $flag) {
- - $flag_type_plugin = $flag->getFlagTypePlugin();
- -
- - // Make sure we're dealing with an entity flag type.
- - if (!$flag_type_plugin instanceof EntityFlagType) {
- - continue;
- - }
- -
- - // Only apply metadata to contextual links if plugin is enabled
- - if (!$flag_type_plugin->showContextualLink()) {
- - continue;
- - }
- -
- - $action = 'flag';
- - if ($flag->isFlagged($entity)) {
- - $action = 'unflag';
- - }
- -
- - $flag_keys[] = $flag->id() . '-' . $action;
- - }
- -
- - if (!empty($flag_keys)) {
- - $build['#contextual_links'][$entity_type]['metadata']['flag_keys'] = implode(',', $flag_keys);
- - }
- - }
- -}
- +// function flag_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
- +// $entity_type = $entity->getEntityTypeId();
- +// if (isset($build['#contextual_links'][$entity_type])) {
- +// /** @var \Drupal\flag\FlagService $flag_service */
- +// $flag_service = \Drupal::service('flag');
- +//
- +// // Get all possible flags for this entity type.
- +// $flags = $flag_service->getAllFlags($entity_type, $entity->bundle());
- +//
- +// foreach ($flags as $flag) {
- +// $flag_type_plugin = $flag->getFlagTypePlugin();
- +//
- +// // Make sure we're dealing with an entity flag type.
- +// if (!$flag_type_plugin instanceof EntityFlagType) {
- +// continue;
- +// }
- +//
- +// // Only apply metadata to contextual links if plugin is enabled
- +// if (!$flag_type_plugin->showContextualLink()) {
- +// continue;
- +// }
- +//
- +// $action = 'flag';
- +// if ($flag->isFlagged($entity)) {
- +// $action = 'unflag';
- +// }
- +//
- +// $flag_keys[] = $flag->id() . '-' . $action;
- +// }
- +//
- +// if (!empty($flag_keys)) {
- +// $build['#contextual_links'][$entity_type]['metadata']['flag_keys'] = implode(',', $flag_keys);
- +// }
- +// }
- +// }
-
- /**
- * Implements hook_contextual_links_alter().
|