Skip to content

Commit

Permalink
add optional urlCallback module property
Browse files Browse the repository at this point in the history
the optional  urlCallback module property can be used to define a list of urls that will be displayed in filemanager angular app  in the item 'copy urls' overlay.
This is the counterpart to the `item.model.urls` addition in dmstr/yii2-filemanager-widgets#16
  • Loading branch information
handcode committed Aug 15, 2022
1 parent 7aab89a commit 01607ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ class Module extends \yii\base\Module
*/
public $thumbnailCallback;


/**
* optional callback that can define a list of urls that will be displayed in filemanager
* backend in the item 'copy urls' overlay.
*
* Return value of the callback has to be an array!
*
* @var null|callable
*/
public $urlCallback;

/**
* @inheritdoc
*
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,22 @@ i.e. `AFM_FILESYSTEM=fsLocal`
\hrzg\filefly\Module::ACCESS_READ => \hrzg\filefly\models\FileflyHashmap::$_all,
\hrzg\filefly\Module::ACCESS_UPDATE => \hrzg\filefly\models\FileflyHashmap::$_all,
\hrzg\filefly\Module::ACCESS_DELETE => \hrzg\filefly\models\FileflyHashmap::$_all,
]
],
# the urlCallbck property can be used to provide customized urls for each file item which (if defined) will overrite
# the default handler URLs
'urlCallback' => function($item) {
$urls = [];
$isImageFileExtList = ['jpg', 'jpeg', 'gif', 'tiff', 'tif', 'svg', 'png', 'bmp'] ;
if ($item['type'] === 'file') {
if (in_array(strtolower($item['extension']), $isImageFileExtList)) {
$urls['image url'] = \dmstr\willnorrisImageproxy\Url::image($item['path']);
}
else {
$urls['download url'] = implode('/', ['/img/download', ltrim($item['path'], '/')]) . ',p1';
}
}
return $urls;
},
],
```

Expand Down
7 changes: 7 additions & 0 deletions controllers/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,15 @@ public function actionList($path)
$thumbnail = '';
}

$itemUrls = [];
if (is_callable($this->module->urlCallback)) {
$itemUrls = call_user_func($this->module->urlCallback, $item);
}

$files[] = [
'name' => $item['basename'],
'path' => $item['path'],
'urls' => $itemUrls,
'thumbnail' => $thumbnail,
'size' => $size,
'date' => date('Y-m-d H:i:s', $time),
Expand Down

0 comments on commit 01607ea

Please sign in to comment.