Esempio n. 1
0
// ACL
$app("acl")->addResource("copilot", ['manage.copilot']);
$app->on('admin.init', function () use($app) {
    if (!$this->module('cockpit')->hasaccess('copilot', ['manage.copilot'])) {
        return;
    }
    // add copilot js lib
    $this->on('app.layout.header', function () {
        // load only within copilot module
        if (strpos($this['route'], '/copilot') !== 0) {
            return;
        }
        // collect page types
        $types = [];
        foreach ([__DIR__ . '/site/types', copi::path('site:site/types'), copi::path('site:site/theme/types')] as $fol) {
            if (!$fol) {
                continue;
            }
            foreach ($this->helper('fs')->ls('*.yaml', $fol) as $file) {
                $type = $file->getBasename('.yaml');
                $types[$type] = $this->helper('yaml')->fromFile($file->getRealPath());
                if (isset($types[$type]['subtypes'])) {
                    foreach ($types[$type]['subtypes'] as $subtype => $def) {
                        $def['parents'] = $type;
                        $types["{$type}/{$subtype}"] = $def;
                    }
                }
            }
        }
        echo '<script>window.COPILOT_PAGE_TYPES = ' . json_encode((object) $types) . '</script>';