|
@@ 273-288 (lines=16) @@
|
| 270 |
|
$entity = $eventArgs->getEntity(); |
| 271 |
|
|
| 272 |
|
//if we remove a BP we need to replace by a VBP ref |
| 273 |
|
if ($entity instanceof BusinessPage) { |
| 274 |
|
//remove BP ref |
| 275 |
|
$event = new ViewReferenceEvent($entity); |
| 276 |
|
$this->dispatcher->dispatch(ViewReferenceEvents::REMOVE_VIEW_REFERENCE, $event); |
| 277 |
|
$em = $eventArgs->getEntityManager(); |
| 278 |
|
$businessTemplate = $entity->getTemplate(); |
| 279 |
|
$page = $this->businessPageBuilder->generateEntityPageFromTemplate( |
| 280 |
|
$businessTemplate, |
| 281 |
|
$entity->getEntity(), |
| 282 |
|
$em |
| 283 |
|
); |
| 284 |
|
//create VBP ref |
| 285 |
|
//TODO :: dont rebuild if businessEntity or businessTemplate doesn't exist |
| 286 |
|
$event = new ViewReferenceEvent($page); |
| 287 |
|
$this->dispatcher->dispatch(ViewReferenceEvents::UPDATE_VIEW_REFERENCE, $event); |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
//if it's a businessEntity, we need to remove all BP and VBP ref |
| 291 |
|
if ($businessEntity = $this->businessEntityHelper->findByEntityInstance($entity)) { |
|
@@ 299-310 (lines=12) @@
|
| 296 |
|
// Generate a viewReference for each BT translation |
| 297 |
|
foreach ($businessTemplate->getTranslations() as $translation) { |
| 298 |
|
$businessTemplate->setCurrentLocale($translation->getLocale()); |
| 299 |
|
if ($page = $em->getRepository('Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage')->findPageByBusinessEntityAndPattern($businessTemplate, $entity, $businessEntity)) { |
| 300 |
|
$event = new ViewReferenceEvent($page); |
| 301 |
|
$this->dispatcher->dispatch(ViewReferenceEvents::REMOVE_VIEW_REFERENCE, $event); |
| 302 |
|
} else { |
| 303 |
|
$page = $this->businessPageBuilder->generateEntityPageFromTemplate( |
| 304 |
|
$businessTemplate, |
| 305 |
|
$entity, |
| 306 |
|
$em |
| 307 |
|
); |
| 308 |
|
$event = new ViewReferenceEvent($page); |
| 309 |
|
$this->dispatcher->dispatch(ViewReferenceEvents::REMOVE_VIEW_REFERENCE, $event); |
| 310 |
|
} |
| 311 |
|
} |
| 312 |
|
} |
| 313 |
|
} |