Guest User

Untitled

a guest
Jan 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. diff --git a/src/ActionLink/ActionLinkTypeBase.php b/src/ActionLink/ActionLinkTypeBase.php
  2. index a14e37e..bc2a154 100644
  3. --- a/src/ActionLink/ActionLinkTypeBase.php
  4. +++ b/src/ActionLink/ActionLinkTypeBase.php
  5. @@ -11,6 +11,7 @@ use Drupal\Core\Cache\CacheableMetadata;
  6. use Drupal\Core\Form\FormStateInterface;
  7. use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
  8. use Drupal\Core\Session\AccountInterface;
  9. +use Drupal\Core\Session\SessionManagerInterface;
  10. use Drupal\Core\StringTranslation\StringTranslationTrait;
  11. use Drupal\flag\FlagInterface;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. @@ -31,6 +32,13 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
  14. */
  15. protected $currentUser;
  16.  
  17. + /**
  18. + * The session manager.
  19. + *
  20. + * @var \Drupal\Core\Session\SessionManagerInterface $sessionManager
  21. + */
  22. + protected $sessionManager;
  23. +
  24. use StringTranslationTrait;
  25. use RedirectDestinationTrait;
  26.  
  27. @@ -45,11 +53,14 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
  28. * The plugin definition array.
  29. * @param \Drupal\Core\Session\AccountInterface $current_user
  30. * The current user.
  31. + * @param \Drupal\Core\Session\SessionManagerInterface $session_manager
  32. + * The session manager.
  33. */
  34. - public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $current_user) {
  35. + public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $current_user, SessionManagerInterface $session_manager) {
  36. parent::__construct($configuration, $plugin_id, $plugin_definition);
  37. $this->configuration += $this->defaultConfiguration();
  38. $this->currentUser = $current_user;
  39. + $this->sessionManager = $session_manager;
  40. }
  41.  
  42. /**
  43. @@ -60,7 +71,8 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
  44. $configuration,
  45. $plugin_id,
  46. $plugin_definition,
  47. - $container->get('current_user')
  48. + $container->get('current_user'),
  49. + $container->get('session_manager')
  50. );
  51. }
  52.  
  53. @@ -144,7 +156,14 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
  54. * @return string
  55. */
  56. protected function getAction(FlagInterface $flag, EntityInterface $entity) {
  57. + // If an anonymous user does not have a session, that user has not yet
  58. + // flagged anything, so the action is "flag".
  59. + if ($this->currentUser->isAnonymous() && !$this->sessionManager->isStarted()) {
  60. + return 'flag';
  61. + }
  62. +
  63. return $flag->isFlagged($entity) ? 'unflag' : 'flag';
  64. +
  65. }
  66.  
  67. /**
Add Comment
Please, Sign In to add comment