Skip to content

Commit

Permalink
Accept a comma separated list of IDs in resourceId (#176)
Browse files Browse the repository at this point in the history
* Accept a comma separated list of IDs in resourceId

That way you could i.e. fill a &resources property of pdoResources with multiple translated resources.

* Wrong variable name

* Don't remove the default value

* Formatting issue
  • Loading branch information
Jako committed Aug 16, 2020
1 parent fd82305 commit 74392d7
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

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

/* get snippet properties */
$resourceId = intval($modx->getOption('resourceId', $scriptProperties));
if (empty($resourceId)) {
$resourceIds = $modx->getOption('resourceId', $scriptProperties);
if (empty($resourceIds)) {
if (!empty($modx->resource) && is_object($modx->resource)) {
$resourceId = $modx->resource->get('id');
$resourceIds = $modx->resource->get('id');
} else {
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($linkedResource[$contextKey])) {
$resource = $modx->getObject('modResource', $linkedResource[$contextKey]);
if ($resource && ($showUnpublished || $resource->get('published') == 1)) {
$output[] = $resource->get('id');
}
}
}
return $output;
return implode(',', $output);

0 comments on commit 74392d7

Please sign in to comment.