Bolt\Legacy\Storage::preFill PHP Method

preFill() public method

Only fill the contenttypes passed as parameters If the parameters is empty, only fill empty tables
See also: preFillSingle
public preFill ( array $contenttypes = [] ) : string
$contenttypes array
return string
    public function preFill($contenttypes = [])
    {
        $output = '';
        // Get a list of images.
        $images = $this->app['filesystem']->find()->in('files://')->name('/\\.jpe?g$/')->name('*.png')->toArray();
        // Set the 'Preferred titles' for filling the 'blocks' contenttype.
        $this->preferredTitles = ['About Us', 'Address', 'Search Teaser', '404 Not Found'];
        $emptyOnly = empty($contenttypes);
        foreach ($this->app['config']->get('contenttypes') as $key => $contenttype) {
            $tablename = $this->getContenttypeTablename($contenttype);
            if ($emptyOnly && $this->hasRecords($tablename)) {
                $output .= Trans::__('Skipped <tt>%key%</tt> (already has records)', ['%key%' => $key]) . "<br>\n";
                continue;
            } elseif (!in_array($key, $contenttypes) && !$emptyOnly) {
                $output .= Trans::__('Skipped <tt>%key%</tt> (not checked)', ['%key%' => $key]) . "<br>\n";
                continue;
            }
            $amount = isset($contenttype['prefill']) ? $contenttype['prefill'] : 5;
            for ($i = 1; $i <= $amount; $i++) {
                $output .= $this->preFillSingle($key, $contenttype, $images);
            }
        }
        $output .= "<br>\n\n" . Trans::__('general.phrase.done-bang');
        return $output;
    }

Usage Example

Example #1
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $this->getService('config')->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $this->setService('prefill', $prefillMock);
     $storage = new Storage($app);
     $storage->preFill(['pages']);
 }