You are here

public function ActionLinkController::unflag in Flag Lists 4.0.x

Same name and namespace in other branches
  1. 8 src/Controller/ActionLinkController.php \Drupal\flag_lists\Controller\ActionLinkController::unflag()

Performs a unflagging when called via a route.

In addition to this it also handles the deletion of the related FlagListItem's.

Parameters

\Drupal\flag\FlagInterface $flag: The flag entity.

int $entity_id: The flaggable entity ID.

string $flag_list: The flag list from the link.

Return value

\Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse|null The response object, only if successful.

See also

\Drupal\flag\Plugin\Reload

\Drupal\flag_lists\Entity\FlagListItem

1 string reference to 'ActionLinkController::unflag'
flag_lists.routing.yml in ./flag_lists.routing.yml
flag_lists.routing.yml

File

src/Controller/ActionLinkController.php, line 135

Class

ActionLinkController
Controller responses to flag and unflag action links.

Namespace

Drupal\flag_lists\Controller

Code

public function unflag(FlagInterface $flag, $entity_id, $flag_list) {

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $this->flagService
    ->getFlaggableById($flag, $entity_id);
  try {
    $this->flagService
      ->unflag($flag, $entity);
  } catch (\LogicException $e) {

    // Fail silently so we return to the entity, which will show an updated
    // link for the existing state of the flag.
  }

  // Remove the flag list item.
  $actionLinkHelper = new ActionLinkHelper($this->flagListsService);
  $actionLinkHelper
    ->unflagHelper($flag, $entity_id, $flag_list);
  return $this
    ->generateResponse($flag, $entity, $flag_list, $flag
    ->getMessage('unflag'));
}