public function import(Type $type, \SimpleXMLElement $element, Package $package = null)
 {
     $loader = new StandardImportLoader();
     $key = new LegacyKey();
     $key->setAttributeType($type);
     $key->setAttributeCategoryEntity($this->getCategoryEntity());
     if (is_object($package)) {
         $key->setPackage($package);
     }
     $loader->load($key, $element);
     $controller = $type->getController();
     $settings = $controller->importKey($element);
     if (!is_object($settings)) {
         $settings = $controller->getAttributeKeySettings();
     }
     $this->entityManager->persist($key);
     $this->entityManager->flush();
     $settings->setAttributeKey($key);
     $key->setAttributeKeySettings($settings);
     $this->entityManager->persist($settings);
     $this->entityManager->flush();
     // Modify the category's search indexer.
     $indexer = $this->getSearchIndexer();
     if (is_object($indexer)) {
         $indexer->updateRepositoryColumns($this, $key);
     }
     $this->entityManager->persist($key);
     $this->entityManager->flush();
 }