/** * Title callback when editing an existing flagging. * * @param \Drupal\flag\FlagInterface $flag * The flag entity. * @param int $entity_id * The entity ID to unflag. * * @return string * The flag field entry form title. */ public function editTitle(FlagInterface $flag, $entity_id) { $link_type = $flag->getLinkTypePlugin(); return $link_type->getEditFlaggingTitle(); }
/** * Generates a response object after handing the un/flag request. * * Depending on the wrapper format of the request, it will either redirect * or return an ajax response. * * @param \Drupal\flag\FlagInterface $flag * The flag entity. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity object. * @param \Symfony\Component\HttpFoundation\Request $request * The request. * * @return \Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse * The response object. */ protected function generateResponse(FlagInterface $flag, EntityInterface $entity, Request $request) { if ($request->get(MainContentViewSubscriber::WRAPPER_FORMAT) == 'drupal_ajax') { // Create a new AJAX response. $response = new AjaxResponse(); // Get the link type plugin. $link_type = $flag->getLinkTypePlugin(); // Generate the link render array and get the link CSS ID. $link = $link_type->getLink($flag, $entity); $link_id = '#' . $link['link']['#attributes']['id']; // Create a new JQuery Replace command to update the link display. $replace = new ReplaceCommand($link_id, $this->renderer->renderPlain($link)); $response->addCommand($replace); return $response; } else { // Redirect back to the entity. A passed in destination query parameter // will automatically override this. $url_info = $entity->toUrl(); return $this->redirect($url_info->getRouteName(), $url_info->getRouteParameters()); } }