You are here

public function FieldEntryFormController::unflag in Flag 8.4

Performs an unflagging when called via a route.

Parameters

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

int $entity_id: The entity ID to unflag.

Return value

array The processed delete form for the given flagging.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Thrown if the flagging could not be found.

See also

\Drupal\flag\Plugin\ActionLink\AJAXactionLink

File

src/Controller/FieldEntryFormController.php, line 135

Class

FieldEntryFormController
Provides a controller for the Field Entry link type.

Namespace

Drupal\flag\Controller

Code

public function unflag(FlagInterface $flag, $entity_id) {
  $entity = $this->flagService
    ->getFlaggableById($flag, $entity_id);

  // If we can't find the flaggable entity, throw a 404.
  if (!$entity) {
    throw new NotFoundHttpException('The flagging could not be found.');
  }

  // Load the flagging. If we can't find it, we can't unflag and throw a 404.
  $flagging = $this->flagService
    ->getFlagging($flag, $entity);
  if (!$flagging) {
    throw new NotFoundHttpException('The flagging could not be found.');
  }
  return $this
    ->getForm($flagging, 'delete');
}