public function addAttributeKey($type, $args, $pkg = false) { if (!is_object($type)) { $type = \Concrete\Core\Attribute\Type::getByHandle($type); } $controller = $type->getController(); $settings = $controller->saveKey($args); if (!is_object($settings)) { $settings = $controller->getAttributeKeySettings(); } // $key is actually an array. $handle = $args['akHandle']; $name = $args['akName']; $key = new LegacyKey(); $key->setAttributeKeyHandle($handle); $key->setAttributeKeyName($name); $key->setAttributeType($type); $this->entityManager->persist($key); $this->entityManager->flush(); $settings->setAttributeKey($key); $this->entityManager->persist($settings); $this->entityManager->flush(); $key->setAttributeKeySettings($settings); $key->setAttributeCategoryEntity($this->getCategoryEntity()); if (is_object($pkg)) { $key->setPackage($pkg); } // Modify the category's search indexer. $indexer = $this->getSearchIndexer(); if (is_object($indexer)) { $indexer->updateRepositoryColumns($this, $key); } $this->entityManager->persist($key); $this->entityManager->flush(); $this->clearAttributeSet($key); if (isset($args['asID']) && $args['asID'] > 0) { $key->setAttributeSet(Set::getByID($args['asID'])); } $this->entityManager->flush(); return $key; }