diff --git a/_build/build.php b/_build/build.php index c24dd11..9553be4 100644 --- a/_build/build.php +++ b/_build/build.php @@ -554,6 +554,38 @@ protected function policy_templates() } + /** + * Add categories + */ + protected function categories() + { + /** @noinspection PhpIncludeInspection */ + $categories = include($this->config['elements'] . 'categories.php'); + if (!is_array($categories)) { + $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not package in Categories'); + + return; + } + $this->category_attributes[xPDOTransport::RELATED_OBJECT_ATTRIBUTES]['Children'] = [ + xPDOTransport::UNIQUE_KEY => 'category', + xPDOTransport::PRESERVE_KEYS => false, + xPDOTransport::UPDATE_OBJECT => !empty($this->config['update']['categories']), + xPDOTransport::RELATED_OBJECTS => true, + xPDOTransport::RELATED_OBJECT_ATTRIBUTES => [], + ]; + $objects = []; + foreach ($categories as $name => $data) { + /** @var modCategory[] $objects */ + $objects[$name] = $this->modx->newObject('modCategory'); + $objects[$name]->fromArray(array_merge([ + 'category' => $name, + ], $data), '', true, true); + } + $this->category->addMany($objects, 'Children'); + $this->modx->log(modX::LOG_LEVEL_INFO, 'Packaged in ' . count($objects) . ' Categories'); + } + + /** * @param $filename * diff --git a/_build/config.inc.php b/_build/config.inc.php index bc307cd..5106c8b 100644 --- a/_build/config.inc.php +++ b/_build/config.inc.php @@ -17,6 +17,7 @@ 'install' => true, // Which elements should be updated on package upgrade 'update' => [ + 'categories' => true, 'chunks' => false, 'menus' => true, 'permission' => true, diff --git a/_build/elements/_categories.php b/_build/elements/_categories.php new file mode 100644 index 0000000..8190cf1 --- /dev/null +++ b/_build/elements/_categories.php @@ -0,0 +1,5 @@ + [], +]; \ No newline at end of file