public function build(array $contentTypeNames, $count, $canExceedMax = false)
    {
        $response = MutableBag::fromRecursive(['created' => [], 'errors' => [], 'warnings' => []]);
        foreach ($contentTypeNames as $contentTypeName) {
            try {
                $existingCount = $this->storage->getRepository($contentTypeName)->count();
            } catch (TableNotFoundException $e) {
                $msg = Trans::__('page.prefill.database-update-required', ['%CONTENTTYPE%' => $contentTypeName]);
                $response->setPath('errors/' . $contentTypeName, $msg);

                continue;
            }

            // If we're over 'max' and we're not skipping "non empty" ContentTypes, show a notice and move on.
            if ($existingCount >= $this->maxCount && !$canExceedMax) {
                $msg = Trans::__('page.prefill.skipped-existing', ['%key%' => $contentTypeName]);
                $response->setPath('warnings/' . $contentTypeName, $msg);

                continue;
            }

            // Singletons are always limited to 1 item max.
            if ($this->contentTypes->getPath($contentTypeName . '/singleton')) {
                if ($existingCount > 0) {
                    $msg = Trans::__('page.prefill.skipped-singleton', ['%key%' => $contentTypeName]);
                    $response->setPath('warnings/' . $contentTypeName, $msg);
                } else {
                    $this->doBuild($contentTypeName, 1, $response);
                }
                continue;
            }

            $createCount = $canExceedMax ? $this->maxCount : $this->maxCount - $existingCount;
            $this->doBuild($contentTypeName, $createCount, $response);
        }

        return $response;
    }
public function build(array $contentTypeNames, $count, $canExceedMax = false)
    {
        $response = MutableBag::fromRecursive(['created' => [], 'errors' => [], 'warnings' => []]);
        foreach ($contentTypeNames as $contentTypeName) {
            try {
                $existingCount = $this->storage->getRepository($contentTypeName)->count();
            } catch (TableNotFoundException $e) {
                $msg = Trans::__('page.prefill.database-update-required', ['%CONTENTTYPE%' => $contentTypeName]);
                $response->setPath('errors/' . $contentTypeName, $msg);

                continue;
            }

            // If we're over 'max' and we're not skipping "non empty" ContentTypes, show a notice and move on.
            if ($existingCount >= $this->maxCount && !$canExceedMax) {
                $msg = Trans::__('page.prefill.skipped-existing', ['%key%' => $contentTypeName]);
                $response->setPath('warnings/' . $contentTypeName, $msg);

                continue;
            }

            // Singletons are always limited to 1 item max.
            if ($this->contentTypes->getPath($contentTypeName . '/singleton')) {
                if ($existingCount > 0) {
                    $msg = Trans::__('page.prefill.skipped-singleton', ['%key%' => $contentTypeName]);
                    $response->setPath('warnings/' . $contentTypeName, $msg);
                } else {
                    $this->doBuild($contentTypeName, 1, $response);
                }
                continue;
            }

            $createCount = $canExceedMax ? $this->maxCount : $this->maxCount - $existingCount;
            $this->doBuild($contentTypeName, $createCount, $response);
        }

        return $response;
    }
public function build ( array $ contentTypeNames , $ count , $ canExceedMax = false ) { $ response = MutableBag :: fromRecursive ( [ 'created' => [ ] , 'errors' => [ ] , 'warnings' => [ ] ] ) ; foreach ( $ contentTypeNames as $ contentTypeName ) { try { $ existingCount = $ this -> storage -> getRepository ( $ contentTypeName ) -> count ( ) ; } catch ( TableNotFoundException $ e ) { $ msg = Trans :: __ ( 'page.prefill.database-update-required' , [ '%CONTENTTYPE%' => $ contentTypeName ] ) ; $ response -> setPath ( 'errors/' . $ contentTypeName , $ msg ) ; continue ; } // If we're over 'max' and we're not skipping "non empty" ContentTypes, show a notice and move on. if ( $ existingCount >= $ this -> maxCount && ! $ canExceedMax ) { $ msg = Trans :: __ ( 'page.prefill.skipped-existing' , [ '%key%' => $ contentTypeName ] ) ; $ response -> setPath ( 'warnings/' . $ contentTypeName , $ msg ) ; continue ; } // Singletons are always limited to 1 item max. if ( $ this -> contentTypes -> getPath ( $ contentTypeName . '/singleton' ) ) { if ( $ existingCount > 0 ) { $ msg = Trans :: __ ( 'page.prefill.skipped-singleton' , [ '%key%' => $ contentTypeName ] ) ; $ response -> setPath ( 'warnings/' . $ contentTypeName , $ msg ) ; } else { $ this -> doBuild ( $ contentTypeName , 1 , $ response ) ; } continue ; } $ createCount = $ canExceedMax ? $ this -> maxCount : $ this -> maxCount - $ existingCount ; $ this -> doBuild ( $ contentTypeName , $ createCount , $ response ) ; } return $ response ; }
Build up-to 'n' number of pre-filled ContentType records.

@param array $contentTypeNames
@param int   $count
@param bool  $canExceedMax

@return MutableBag
Build up - to n number of pre - filled ContentType records .