/**
  * Check if the attribute is removable, otherwise throw an exception or redirect
  *
  * @param AttributeInterface $attribute
  *
  * @throws DeleteException For ajax requests if the attribute is not removable
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
  */
 protected function validateRemoval(AttributeInterface $attribute)
 {
     if (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
         $errorMessage = 'flash.attribute.identifier not removable';
         $messageParameters = [];
     } else {
         $groupCount = $this->groupRepository->countVariantGroupAxis($attribute);
         if ($groupCount > 0) {
             $errorMessage = 'flash.attribute.used by groups';
             $messageParameters = ['%count%' => $groupCount];
         }
     }
     if (isset($errorMessage)) {
         if ($this->getRequest()->isXmlHttpRequest()) {
             throw new DeleteException($this->getTranslator()->trans($errorMessage, $messageParameters));
         } else {
             $this->addFlash($errorMessage, $messageParameters);
             return $this->redirectToRoute('pim_enrich_attribute_index');
         }
     }
 }