$form->handleRequest($request);
if ($form->isValid()) {
- // check for existing entry, if it exists, redirect to it with a message
- $existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
+ $existingEntry = $this->checkIfEntryAlreadyExists($entry);
if (false !== $existingEntry) {
$this->get('session')->getFlashBag()->add(
'notice',
- $this->get('translator')->trans('flashes.entry.notice.entry_already_saved', array('%date%' => $existingEntry->getCreatedAt()->format('d-m-Y')))
+ $this->get('translator')->trans('flashes.entry.notice.entry_already_saved', ['%date%' => $existingEntry->getCreatedAt()->format('d-m-Y')])
);
- return $this->redirect($this->generateUrl('view', array('id' => $existingEntry->getId())));
+ return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()]));
}
$this->updateEntry($entry);
return $this->redirect($this->generateUrl('homepage'));
}
- return $this->render('WallabagCoreBundle:Entry:new_form.html.twig', array(
+ return $this->render('WallabagCoreBundle:Entry:new_form.html.twig', [
'form' => $form->createView(),
- ));
+ ]);
}
/**
$entry = new Entry($this->getUser());
$entry->setUrl($request->get('url'));
- // check for existing entry, if it exists, redirect to it with a message
- $existingEntry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
-
- if (false === $existingEntry) {
+ if (false === $this->checkIfEntryAlreadyExists($entry)) {
$this->updateEntry($entry);
}
'flashes.entry.notice.entry_updated'
);
- return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
+ return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
- return $this->render('WallabagCoreBundle:Entry:edit.html.twig', array(
+ return $this->render('WallabagCoreBundle:Entry:edit.html.twig', [
'form' => $form->createView(),
- ));
+ ]);
}
/**
$entries->setCurrentPage($page);
} catch (OutOfRangeCurrentPageException $e) {
if ($page > 1) {
- return $this->redirect($this->generateUrl($type, array('page' => $entries->getNbPages())), 302);
+ return $this->redirect($this->generateUrl($type, ['page' => $entries->getNbPages()]), 302);
}
}
return $this->render(
'WallabagCoreBundle:Entry:entries.html.twig',
- array(
+ [
'form' => $form->createView(),
'entries' => $entries,
'currentPage' => $page,
- )
+ ]
);
}
return $this->render(
'WallabagCoreBundle:Entry:entry.html.twig',
- array('entry' => $entry)
+ ['entry' => $entry]
);
}
$message
);
- return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
+ return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
/**
// to avoid redirecting to the deleted entry. Ugh.
$url = $this->generateUrl(
'view',
- array('id' => $entry->getId()),
+ ['id' => $entry->getId()],
UrlGeneratorInterface::ABSOLUTE_URL
);
throw $this->createAccessDeniedException('You can not access this entry.');
}
}
+
+ /**
+ * Check for existing entry, if it exists, redirect to it with a message.
+ *
+ * @param Entry $entry
+ *
+ * @return Entry|bool
+ */
+ private function checkIfEntryAlreadyExists(Entry $entry)
+ {
+ return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
+ }
}