<commit_before><?php

namespace BoomCMS\Core\Chunk;

use BoomCMS\Core\Page;
use BoomCMS\Core\Facades\Chunk;

class ChunkLoader
{
    protected $chunks;
    protected$page;

    public function __construct(Page\Page $page, array $chunks)
    {
        $this->chunks = $chunks;
        $this->page = $page;
    }

    public function getChunks()
    {
        foreach ($this->chunks as $type => $slotnames) {
            $model = ucfirst($type);
            $class = "\BoomCMS\Core\Chunk\\" . $model;

            $models = Chunk::find($type, $slotnames, $this->page->getCurrentVersion());
            $found = [];

            foreach ($models as $m) {
                if ($m) {
                    $found[] = $m->slotname;
                    $this->chunks[$type][$m->slotname] = new $class($this->page, $m->toArray(), $m->slotname, true);
                }
            }

            $not_found = array_diff($slotnames, $found);
            foreach ($not_found as $slotname) {
                $this->chunks[$type][$slotname] = new $class($this->page, [], $slotname, true);
            }
        }

        return $this->chunks;
    }
}<commit_msg>Bugfix: default chunk content appearing when editor not enabled<commit_after><?php

namespace BoomCMS\Core\Chunk;

use BoomCMS\Core\Page;
use BoomCMS\Core\Facades\Editor;
use BoomCMS\Core\Facades\Chunk;

class ChunkLoader
{
    protected $chunks;
    protected $page;

    public function __construct(Page\Page $page, array $chunks)
    {
        $this->chunks = $chunks;
        $this->page = $page;
    }

    public function getChunks()
    {
        foreach ($this->chunks as $type => $slotnames) {
            $model = ucfirst($type);
            $class = "\BoomCMS\Core\Chunk\\" . $model;

            $models = Chunk::find($type, $slotnames, $this->page->getCurrentVersion());
            $found = [];

            foreach ($models as $m) {
                if ($m) {
                    $found[] = $m->slotname;
                    $this->chunks[$type][$m->slotname] = new $class($this->page, $m->toArray(), $m->slotname, Editor::isEnabled());
                }
            }

            $not_found = array_diff($slotnames, $found);
            foreach ($not_found as $slotname) {
                $this->chunks[$type][$slotname] = new $class($this->page, [], $slotname, Editor::isEnabled());
            }
        }

        return $this->chunks;
    }
}
{'fraction_non_alphanumeric': 0.16058091286307055, 'fraction_numerical': 0.0, 'mean_word_length': 1.958282208588957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3817239', 'n_tokens_mistral': 768, 'n_tokens_neox': 736, 'n_words': 147}