concrete/src/Attribute/Category/AbstractCategory.php
public function add($type, $key, $settings = null, $pkg = null)
    {
        if (is_string($type)) {
            $typeFactory = $this->application->make(TypeFactory::class);
            /* @var TypeFactory $typeFactory */
            $type = $typeFactory->getByHandle($type);
        }

        // Legacy array support for $key
        $asID = false;
        if (is_array($key)) {
            $handle = $key['akHandle'];
            $name = $key['akName'];
            if (isset($key['asID'])) {
                $asID = $key['asID'];
            }
            $key = $this->createAttributeKey();
            $key->setAttributeKeyHandle($handle);
            $key->setAttributeKeyName($name);
        }

        // Legacy support for third parameter which used to be package
        if ($settings instanceof Package || $settings instanceof \Concrete\Core\Package\Package) {
            $pkg = $settings;
            $settings = null;
        }

        if (!$settings) {
            $settings = $type->getController()->getAttributeKeySettings();
        }

        $key->setAttributeType($type);
        $this->entityManager->persist($key);
        $this->entityManager->flush();

        $settings->setAttributeKey($key);
        $key->setAttributeKeySettings($settings);

        $this->entityManager->persist($settings);
        $this->entityManager->flush();

        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();

        /* legacy support, attribute set */

        if ($asID) {
            $manager = $this->getSetManager();
            $factory = new SetFactory($this->entityManager);
            $set = $factory->getByID($asID);
            if ($set !== null) {
                $manager->addKey($set, $key);
            }
        }

        return $key;
    }
public function add($type, $key, $settings = null, $pkg = null)
    {
        if (is_string($type)) {
            $typeFactory = $this->application->make(TypeFactory::class);
            /* @var TypeFactory $typeFactory */
            $type = $typeFactory->getByHandle($type);
        }

        // Legacy array support for $key
        $asID = false;
        if (is_array($key)) {
            $handle = $key['akHandle'];
            $name = $key['akName'];
            if (isset($key['asID'])) {
                $asID = $key['asID'];
            }
            $key = $this->createAttributeKey();
            $key->setAttributeKeyHandle($handle);
            $key->setAttributeKeyName($name);
        }

        // Legacy support for third parameter which used to be package
        if ($settings instanceof Package || $settings instanceof \Concrete\Core\Package\Package) {
            $pkg = $settings;
            $settings = null;
        }

        if (!$settings) {
            $settings = $type->getController()->getAttributeKeySettings();
        }

        $key->setAttributeType($type);
        $this->entityManager->persist($key);
        $this->entityManager->flush();

        $settings->setAttributeKey($key);
        $key->setAttributeKeySettings($settings);

        $this->entityManager->persist($settings);
        $this->entityManager->flush();

        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();

        /* legacy support, attribute set */

        if ($asID) {
            $manager = $this->getSetManager();
            $factory = new SetFactory($this->entityManager);
            $set = $factory->getByID($asID);
            if ($set !== null) {
                $manager->addKey($set, $key);
            }
        }

        return $key;
    }
public function add ( $ type , $ key , $ settings = null , $ pkg = null ) { if ( is_string ( $ type ) ) { $ typeFactory = $ this -> application -> make ( TypeFactory :: class ) ; /* @var TypeFactory $typeFactory */ $ type = $ typeFactory -> getByHandle ( $ type ) ; } // Legacy array support for $key $ asID = false ; if ( is_array ( $ key ) ) { $ handle = $ key [ 'akHandle' ] ; $ name = $ key [ 'akName' ] ; if ( isset ( $ key [ 'asID' ] ) ) { $ asID = $ key [ 'asID' ] ; } $ key = $ this -> createAttributeKey ( ) ; $ key -> setAttributeKeyHandle ( $ handle ) ; $ key -> setAttributeKeyName ( $ name ) ; } // Legacy support for third parameter which used to be package if ( $ settings instanceof Package || $ settings instanceof \ Concrete \ Core \ Package \ Package ) { $ pkg = $ settings ; $ settings = null ; } if ( ! $ settings ) { $ settings = $ type -> getController ( ) -> getAttributeKeySettings ( ) ; } $ key -> setAttributeType ( $ type ) ; $ this -> entityManager -> persist ( $ key ) ; $ this -> entityManager -> flush ( ) ; $ settings -> setAttributeKey ( $ key ) ; $ key -> setAttributeKeySettings ( $ settings ) ; $ this -> entityManager -> persist ( $ settings ) ; $ this -> entityManager -> flush ( ) ; 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 ( ) ; /* legacy support, attribute set */ if ( $ asID ) { $ manager = $ this -> getSetManager ( ) ; $ factory = new SetFactory ( $ this -> entityManager ) ; $ set = $ factory -> getByID ( $ asID ) ; if ( $ set !== null ) { $ manager -> addKey ( $ set , $ key ) ; } } return $ key ; }
Add a new attribute key.

@param \Concrete\Core\Entity\Attribute\Type|string $type the attribute type (or its handle)
@param \Concrete\Core\Entity\Attribute\Key\Key|array $key an empty attribute key, or an array with keys 'akHandle' (the attribute key handle), 'akName' (the attribute key name) and optionally 'asID' (the ID of the attribute set)
@param \Concrete\Core\Entity\Attribute\Key\Settings\Settings|null $settings the attribute key settings (if not specified, a new settings instance will be created)
@param \Concrete\Core\Entity\Package|null $pkg the entity of the package that's creating the attribute key

@return \Concrete\Core\Entity\Attribute\Key\Key
Add a new attribute key .