You are here

public static function Heartbeat::flagAjaxMarkup in Heartbeat 8

File

src/Entity/Heartbeat.php, line 833

Class

Heartbeat

Namespace

Drupal\heartbeat\Entity

Code

public static function flagAjaxMarkup($flagId, $entity, FlagService $flagService) {
  $flag = $flagService
    ->getFlagById($flagId);
  $link = $flag
    ->getLinkTypePlugin()
    ->getAsLink($flag, $entity);
  $options = $link
    ->getUrl()
    ->getOptions();
  $options['query']['destination'] = 'node';
  $link
    ->getUrl()
    ->setOptions($options);
  $action = $flag
    ->getLinkTypePlugin()
    ->getAsFlagLink($flag, $entity)['#action'];

  //    if ($action) {
  $url = $link
    ->getUrl()
    ->toString();
  return '<div class="flag flag-' . $flagId . '  flag-' . $flagId . '-' . $entity
    ->id() . ' action-' . $action . '"><a href="' . $url . '" class="use-ajax" rel="nofollow"></a></div>';

  //    } else {
  //      return null;
  //    }
}