public function prefill(Request $request)
    {
        // Determine the ContentTypes that we're doing the prefill for
        $choices = [];
        foreach ($this->getOption('contenttypes') as $key => $contentType) {
            $nameKey = 'contenttypes.' . $key . '.name.plural';
            $nameTrans = Trans::__($nameKey, [], 'contenttypes');
            $name = ($nameTrans === $nameKey) ? $contentType['name'] : $nameTrans;
            $choices[$name] = $key;
        }

        // Create the form
        $options = [
            'attr'         => ['data-bind' => '{"bind":"prefill"}'],
            'contenttypes' => $choices,
        ];
        $form = $this->createFormBuilder(PrefillType::class, [], $options)
            ->getForm()
        ;

        if ($request->isMethod('POST') || $request->query->getBoolean('force')) {
            $form->handleRequest($request);
            $contentTypeNames = (array) $form->get('contenttypes')->getData();

            // ✓ - If the DB is empty
            // ✓ - If ContentType(s) *are* selected
            // ✓ - If *no* ContentTypes are selected *and* a ContentType's record count < max
            // X - If *no* ContentTypes are selected *and* a ContentType's record count >= max
            $canExceedMax = true;
            if (count($contentTypeNames) === 0) {
                $contentTypeNames = $choices;
                $canExceedMax = false;
            }

            $builder = $this->app['prefill.builder'];
            $results = $builder->build($contentTypeNames, 5, $canExceedMax);
            $this->session()->set('prefill_result', $results);

            return $this->redirectToRoute('prefill');
        }

        $prefillResult = $this->session()->remove('prefill_result') ?: ['created' => null, 'errors' => null, 'warnings' => null];
        $context = [
            'contenttypes' => $choices,
            'form'         => $form->createView(),
            'results'      => $prefillResult,
        ];

        return $this->render('@bolt/prefill/prefill.twig', $context);
    }
public function prefill(Request $request)
    {
        // Determine the ContentTypes that we're doing the prefill for
        $choices = [];
        foreach ($this->getOption('contenttypes') as $key => $contentType) {
            $nameKey = 'contenttypes.' . $key . '.name.plural';
            $nameTrans = Trans::__($nameKey, [], 'contenttypes');
            $name = ($nameTrans === $nameKey) ? $contentType['name'] : $nameTrans;
            $choices[$name] = $key;
        }

        // Create the form
        $options = [
            'attr'         => ['data-bind' => '{"bind":"prefill"}'],
            'contenttypes' => $choices,
        ];
        $form = $this->createFormBuilder(PrefillType::class, [], $options)
            ->getForm()
        ;

        if ($request->isMethod('POST') || $request->query->getBoolean('force')) {
            $form->handleRequest($request);
            $contentTypeNames = (array) $form->get('contenttypes')->getData();

            // ✓ - If the DB is empty
            // ✓ - If ContentType(s) *are* selected
            // ✓ - If *no* ContentTypes are selected *and* a ContentType's record count < max
            // X - If *no* ContentTypes are selected *and* a ContentType's record count >= max
            $canExceedMax = true;
            if (count($contentTypeNames) === 0) {
                $contentTypeNames = $choices;
                $canExceedMax = false;
            }

            $builder = $this->app['prefill.builder'];
            $results = $builder->build($contentTypeNames, 5, $canExceedMax);
            $this->session()->set('prefill_result', $results);

            return $this->redirectToRoute('prefill');
        }

        $prefillResult = $this->session()->remove('prefill_result') ?: ['created' => null, 'errors' => null, 'warnings' => null];
        $context = [
            'contenttypes' => $choices,
            'form'         => $form->createView(),
            'results'      => $prefillResult,
        ];

        return $this->render('@bolt/prefill/prefill.twig', $context);
    }
public function prefill ( Request $ request ) { // Determine the ContentTypes that we're doing the prefill for $ choices = [ ] ; foreach ( $ this -> getOption ( 'contenttypes' ) as $ key => $ contentType ) { $ nameKey = 'contenttypes.' . $ key . '.name.plural' ; $ nameTrans = Trans :: __ ( $ nameKey , [ ] , 'contenttypes' ) ; $ name = ( $ nameTrans === $ nameKey ) ? $ contentType [ 'name' ] : $ nameTrans ; $ choices [ $ name ] = $ key ; } // Create the form $ options = [ 'attr' => [ 'data-bind' => '{"bind":"prefill"}' ] , 'contenttypes' => $ choices , ] ; $ form = $ this -> createFormBuilder ( PrefillType :: class , [ ] , $ options ) -> getForm ( ) ; if ( $ request -> isMethod ( 'POST' ) || $ request -> query -> getBoolean ( 'force' ) ) { $ form -> handleRequest ( $ request ) ; $ contentTypeNames = ( array ) $ form -> get ( 'contenttypes' ) -> getData ( ) ; // ✓ - If the DB is empty // ✓ - If ContentType(s) *are* selected // ✓ - If *no* ContentTypes are selected *and* a ContentType's record count < max // X - If *no* ContentTypes are selected *and* a ContentType's record count >= max $ canExceedMax = true ; if ( count ( $ contentTypeNames ) === 0 ) { $ contentTypeNames = $ choices ; $ canExceedMax = false ; } $ builder = $ this -> app [ 'prefill.builder' ] ; $ results = $ builder -> build ( $ contentTypeNames , 5 , $ canExceedMax ) ; $ this -> session ( ) -> set ( 'prefill_result' , $ results ) ; return $ this -> redirectToRoute ( 'prefill' ) ; } $ prefillResult = $ this -> session ( ) -> remove ( 'prefill_result' ) ? : [ 'created' => null , 'errors' => null , 'warnings' => null ] ; $ context = [ 'contenttypes' => $ choices , 'form' => $ form -> createView ( ) , 'results' => $ prefillResult , ] ; return $ this -> render ( '@bolt/prefill/prefill.twig' , $ context ) ; }
Generate Lorem Ipsum records in the database for given ContentTypes.

@param Request $request The Symfony Request

@return \Bolt\Response\TemplateResponse|\Symfony\Component\HttpFoundation\RedirectResponse
Generate Lorem Ipsum records in the database for given ContentTypes .