Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding subcategories to the main category #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions _build/build.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions _build/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'install' => true,
// Which elements should be updated on package upgrade
'update' => [
'categories' => true,
'chunks' => false,
'menus' => true,
'permission' => true,
Expand Down
5 changes: 5 additions & 0 deletions _build/elements/_categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'modExtraCategoryExample' => [],
];