protected function prepareData(ClassMetadata $metadata, array $data)
 {
     foreach ($data as $name => &$entityData) {
         switch ($metadata->name) {
             case Localization::CN():
             case PageLocalization::CN():
             case TemplateLocalization::CN():
             case ApplicationLocalization::CN():
                 $entityData['publishedRevision'] = null;
                 $args = array($entityData['locale']);
                 break;
             case PageLocalizationPath::CN():
                 $args = array(str_ireplace('pageLocalizationPath', '', $name), $entityData['locale']);
                 break;
             case TemplateLayout::CN():
                 $args = array($entityData['media']);
                 break;
             case BlockPropertyMetadata::CN():
                 $args = array($entityData['name'], $entityData['blockProperty']);
                 break;
             case BlockProperty::CN():
                 $args = array($entityData['name']);
                 break;
             case PagePlaceHolder::CN():
             case TemplatePlaceHolder::CN():
                 $args = array($entityData['name']);
                 break;
             default:
                 $constructor = new \ReflectionMethod($metadata->name, '__construct');
                 if ($constructor->getNumberOfRequiredParameters() === 0) {
                     return parent::prepareData($metadata, $data);
                 }
                 throw new \RuntimeException(sprintf('Don\'t know how to build constructor required for [%s].', $metadata->name));
         }
         $entityData = array_merge(array('__construct' => $args), $entityData);
     }
     return parent::prepareData($metadata, $data);
 }
 /**
  * Throws exception if page duplicate is found
  * @param PageLocalization $pageData
  * @param Path $newPath
  */
 protected function checkForDuplicates(PageLocalization $pageData, Path $newPath)
 {
     $page = $pageData->getMaster();
     $locale = $pageData->getLocale();
     $repo = $this->em->getRepository(PageLocalizationPath::CN());
     $newPathString = $newPath->getFullPath();
     // Duplicate path validation
     $criteria = array('locale' => $locale, 'path' => $newPath);
     $duplicate = $repo->findOneBy($criteria);
     /* @var $duplicate PageLocalizationPath */
     if (!is_null($duplicate) && !$pageData->getPathEntity()->equals($duplicate)) {
         throw new DuplicatePagePathException(sprintf('Page with path [%s] already exists.', $newPathString), $pageData);
     }
 }