Skip to content
New issue

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

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

Already on GitHub? # to your account

Accept a comma separated list of IDs in resourceId #176

Merged
merged 4 commits into from
Aug 16, 2020
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Babel
*
Expand Down Expand Up @@ -41,28 +40,27 @@
return;

/* get snippet properties */
$resourceId = intval($modx->getOption('resourceId', $scriptProperties));
if (empty($resourceId)) {
if (!empty($modx->resource) && is_object($modx->resource)) {
$resourceId = $modx->resource->get('id');
} else {
return;
}
$resourceIds = $modx->getOption('resourceId', $scriptProperties);
if (empty($resourceIds)) {
return;
}
$resourceIds = array_map('trim', explode(',', $resourceIds));;
$contextKey = $modx->getOption('contextKey', $scriptProperties, '', true);
if (empty($contextKey)) {
$cultureKey = $modx->getOption('cultureKey', $scriptProperties, '', true);
$contextKey = $babel->getContextKey($cultureKey);
}
$showUnpublished = $modx->getOption('showUnpublished', $scriptProperties, 0, true);

/* determine id of tranlated resource */
$linkedResources = $babel->getLinkedResources($resourceId);
$output = null;
if (isset($linkedResources[$contextKey])) {
$resource = $modx->getObject('modResource', $linkedResources[$contextKey]);
if ($resource && ($showUnpublished || $resource->get('published') == 1)) {
$output = $resource->get('id');
/* determine ids of translated resource */
$output = array();
foreach($resourceIds as $resourceId) {
$linkedResource = $babel->getLinkedResources($resourceId);
if (isset($linkedResources[$contextKey])) {
$resource = $modx->getObject('modResource', $linkedResources[$contextKey]);
if ($resource && ($showUnpublished || $resource->get('published') == 1)) {
$output[] = $resource->get('id');
}
}
}
return $output;
return implode(',', $output);