/**
  * @param object                        $entity
  * @param ActivityListProviderInterface $provider
  * @param string                        $verb
  * @param ActivityList|null             $list
  *
  * @return ActivityList
  */
 protected function getActivityListEntityForEntity($entity, ActivityListProviderInterface $provider, $verb = ActivityList::VERB_CREATE, $list = null)
 {
     if ($provider->isApplicable($entity)) {
         if (!$list) {
             $list = new ActivityList();
         }
         $list->setSubject($provider->getSubject($entity));
         $description = $this->htmlTagHelper->stripTags($this->htmlTagHelper->purify($provider->getDescription($entity)));
         $list->setDescription($description);
         if ($this->hasCustomDate($provider)) {
             $list->setCreatedAt($provider->getDate($entity));
             $list->setUpdatedAt($provider->getDate($entity));
         }
         if ($this->hasGrouping($provider)) {
             $list->setHead($provider->isHead($entity));
         }
         $list->setVerb($verb);
         if ($verb === ActivityList::VERB_UPDATE) {
             $activityListTargets = $list->getActivityListTargetEntities();
             foreach ($activityListTargets as $target) {
                 $list->removeActivityListTarget($target);
             }
         } else {
             $className = $this->doctrineHelper->getEntityClass($entity);
             $list->setRelatedActivityClass($className);
             $list->setRelatedActivityId($this->doctrineHelper->getSingleEntityIdentifier($entity));
             $list->setOrganization($provider->getOrganization($entity));
         }
         $targets = $provider->getTargetEntities($entity);
         foreach ($targets as $target) {
             if ($list->supportActivityListTarget($this->doctrineHelper->getEntityClass($target))) {
                 $list->addActivityListTarget($target);
             }
         }
         return $list;
     }
     return null;
 }