删除元素之前的条件[symfony2]

A user can have an album that contains many pictures, he can delete the picture or upload a new picture. I would like the album to have 1 or more picture,but never null (0). So before the user to delete a picture I want to be able to check if the amount of picture is more than one, if it's less than one display a flashbag message notifying the user that he can't have 0 picture in his album.

This what I have done:

/**
 * @Security("has_role('ROLE_USER')")
 */
public function avatarUserDeletedAction($id)
{
    $em = $this->getDoctrine()->getManager();
    $entity = $em->getRepository('ApplicationSonataUserBundle:Avatar')->find($id);

    if ($this->container->get('security.token_storage')->getToken()->getUser() != $entity->getUser() || !$entity)
        return $this->redirect($this->generateUrl('avatarUser'));

    $em->remove($entity);
    $em->flush();

    return $this->redirect($this->generateUrl('avatarUser'));
    //return $this->redirectToRoute('avatarUser');
}

ADD:

/**
 * @Security("has_role('ROLE_USER')")
 */
public function avatarUserDeletedAction(Request $request,$id)
{
    $em = $this->getDoctrine()->getManager();
    $entity = $em->getRepository('ApplicationSonataUserBundle:Avatar')->find($id);

    if ($entity == 1) {
        $request->getSession()
            ->getFlashBag()
            ->add('success', 'You cannot have less than 1 picture');
    } else{
        if ($this->container->get('security.token_storage')->getToken()->getUser() != $entity->getUser() || !$entity)
            return $this->redirect($this->generateUrl('avatarUser'));
        $em->remove($entity);
        $em->flush();
        }
    return $this->redirect($this->generateUrl('avatarUser'));
    //return $this->redirectToRoute('avatarUser');
}

I have the error below:

Notice: Object of class Application\Sonata\UserBundle\Entity\Avatar could not be converted to int

What about this?

public function avatarUserDeletedAction($id)
{
    $em = $this->getDoctrine()->getManager();
    $entity = $em->getRepository('ApplicationSonataUserBundle:Avatar')->find($id);
    $qb = $em->createQueryBuilder();
    $qb->select('count(entity.id)');    
    $qb->from('ApplicationSonataUserBundle:Avatar','entity');

    $count = $qb->getQuery()->getSingleScalarResult();

    if ($this->container->get('security.token_storage')->getToken()->getUser() != $entity->getUser() || !$entity)
        return $this->redirect($this->generateUrl('avatarUser'));

    if($count >= 2) {
        $em->remove($entity);
        $em->flush();    
    }
    else {
        //generate error indicating user that can't have zero elements in the album 
    }

    return $this->redirect($this->generateUrl('avatarUser'));
    //return $this->redirectToRoute('avatarUser');
}

you need to count how many items in the list $entity you actually making a condition on an $entity;

your condition should be executed on an int

$entityCount= count ($entity);