/**
   * {@inheritdoc}
   */
  public function getLink(FlagInterface $flag, EntityInterface $entity) {
    $action = $flag->isFlagged($entity) ? 'unflag' : 'flag';

    if ($flag->hasActionAccess($action)) {

      $link = $this->buildLink($action, $flag, $entity);

      // The actual render array must be in a nested key, due to a bug in
      // lazy builder handling that does not properly render top-level #type
      // elements.
      return ['link' => $link];
    }

    return [];
  }