/**
* Helper function for patch action.
*
* @param $item
*
* @throws \Sulu\Component\Rest\Exception\EntityNotFoundException
*
* @return Position added or updated entity
*/
private function addAndUpdateTitles($item)
{
if (isset($item['id']) && !empty($item['id'])) {
/* @var Position $position */
$position = $this->getDoctrine()->getRepository(self::$entityName)->find($item['id']);
if ($position == null) {
throw new EntityNotFoundException(self::$entityName, $item['id']);
} else {
$position->setPosition($item['position']);
}
} else {
$position = new Position();
$position->setPosition($item['position']);
$this->getDoctrine()->getManager()->persist($position);
}
return $position;
}