/**
  * @param RemoveEvent $event
  */
 public function preRemove(RemoveEvent $event)
 {
     $subject = $event->getSubject();
     if (!$subject instanceof AttributeInterface) {
         return;
     }
     $productTemplates = $this->productTplRepository->findByAttribute($subject);
     foreach ($productTemplates as $productTemplate) {
         $this->productTplBuilder->removeAttribute($productTemplate, $subject);
         $attributeCodes = $productTemplate->getAttributeCodes();
         if (empty($attributeCodes)) {
             $this->objectManager->remove($productTemplate);
         } else {
             $this->objectManager->persist($productTemplate);
         }
     }
 }