Skip to content

Commit

Permalink
ACP-4056 Added interface to expands actions on file info view page. (…
Browse files Browse the repository at this point in the history
…#11134)

ACP-4056 Added interface to expands actions on file info view page.
  • Loading branch information
vol4onok authored Oct 11, 2024
1 parent fb1ca52 commit 8f93e20
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 5 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ trim_trailing_whitespace = true

[*.bat]
end_of_line = crlf

2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ tooling.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
architecture-baseline.json export-ignore
.github/ export-ignore
architecture-baseline.json export-ignore
2 changes: 1 addition & 1 deletion codeception.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace: SprykerTest
paths:
tests: tests/
output: tests/_output/
log: tests/_output/
data: tests/_data/
support: tests/_support/
envs: tests/_envs/
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"php": ">=8.2",
"spryker/file-manager": "^2.3.0",
"spryker/file-manager-gui-extension": "^1.0.0",
"spryker/file-system-extension": "^1.0.0",
"spryker/gui": "^3.45.0",
"spryker/kernel": "^3.30.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@
<transfer name="Locale">
</transfer>

<transfer name="Button">
<property name="url" type="string"/>
<property name="title" type="string"/>
<property name="defaultOptions" type="array" singular="defaultOptions"/>
<property name="customOptions" type="array" singular="customOptions"/>
</transfer>
</transfers>
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function createFileInfoViewTable(int $idFile)
return new FileInfoViewTable(
$this->getFileInfoQuery(),
$idFile,
$this->getTableActionsExpanderPlugins(),
);
}

Expand Down Expand Up @@ -264,4 +265,12 @@ protected function getMimeTypeQuery()
{
return $this->getProvidedDependency(FileManagerGuiDependencyProvider::PROPEL_QUERY_MIME_TYPE);
}

/**
* @return array<\Spryker\Zed\FileManagerGuiExtension\Dependency\Plugin\FileInfoViewTableActionsExpanderPluginInterface>
*/
protected function getTableActionsExpanderPlugins(): array
{
return $this->getProvidedDependency(FileManagerGuiDependencyProvider::PLUGINS_FILE_INFO_VIEW_TABLE_ACTIONS_EXPANDER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,33 @@

namespace Spryker\Zed\FileManagerGui\Communication\Table;

use Orm\Zed\FileManager\Persistence\SpyFileInfoQuery;
use Spryker\Service\UtilText\Model\Url\Url;

class FileInfoViewTable extends FileInfoTable
{
/**
* @param array $item
* @var array<\Spryker\Zed\FileManagerGuiExtension\Dependency\Plugin\FileInfoViewTableActionsExpanderPluginInterface>
*/
protected array $tableActionsExpanderPlugins;

/**
* @param \Orm\Zed\FileManager\Persistence\SpyFileInfoQuery $fileInfoQuery
* @param int $idFile
* @param array<\Spryker\Zed\FileManagerGuiExtension\Dependency\Plugin\FileInfoViewTableActionsExpanderPluginInterface> $tableActionsExpanderPlugins
*/
public function __construct(
SpyFileInfoQuery $fileInfoQuery,
int $idFile,
array $tableActionsExpanderPlugins
) {
parent::__construct($fileInfoQuery, $idFile);

$this->tableActionsExpanderPlugins = $tableActionsExpanderPlugins;
}

/**
* @param array<mixed> $item
*
* @return array<string>
*/
Expand All @@ -27,6 +48,44 @@ protected function buildLinks($item)
'Download',
);

return $buttons;
return $this->expandLinks($item, $buttons);
}

/**
* @param array<string, mixed> $item
* @param array<string> $buttons
*
* @return array<string>
*/
protected function expandLinks(array $item, array $buttons): array
{
$buttonCollection = [];

foreach ($this->tableActionsExpanderPlugins as $tableActionsExpanderPlugin) {
$buttonCollection = $tableActionsExpanderPlugin->execute($item, $buttonCollection);
}

return array_merge($buttons, $this->generateButtons($buttonCollection));
}

/**
* @param array<\Generated\Shared\Transfer\ButtonTransfer> $buttonTransferCollection
*
* @return array<string>
*/
protected function generateButtons(array $buttonTransferCollection): array
{
$generatedButtons = [];

foreach ($buttonTransferCollection as $buttonTransfer) {
$generatedButtons[] = $this->generateButton(
$buttonTransfer->getUrlOrFail(),
$buttonTransfer->getTitleOrFail(),
$buttonTransfer->getDefaultOptions(),
$buttonTransfer->getCustomOptions(),
);
}

return $generatedButtons;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class FileManagerGuiDependencyProvider extends AbstractBundleDependencyProvider
*/
public const SERVICE_UTIL_ENCODING = 'SERVICE_UTIL_ENCODING';

/**
* @var string
*/
public const PLUGINS_FILE_INFO_VIEW_TABLE_ACTIONS_EXPANDER = 'PLUGINS_FILE_INFO_VIEW_TABLE_ACTIONS_EXPANDER';

/**
* @param \Spryker\Zed\Kernel\Container $container
*
Expand All @@ -64,6 +69,7 @@ public function provideCommunicationLayerDependencies(Container $container)
$container = $this->addLocaleFacade($container);
$container = $this->addQueries($container);
$container = $this->addUtilEncodingService($container);
$container = $this->addTableActionsExpanderPlugins($container);

return $container;
}
Expand Down Expand Up @@ -171,4 +177,26 @@ protected function addUtilEncodingService(Container $container): Container

return $container;
}

/**
* @param \Spryker\Zed\Kernel\Container $container
*
* @return \Spryker\Zed\Kernel\Container
*/
protected function addTableActionsExpanderPlugins(Container $container): Container
{
$container->set(static::PLUGINS_FILE_INFO_VIEW_TABLE_ACTIONS_EXPANDER, function () {
return $this->getFileInfoViewTableActionsExpanderPlugins();
});

return $container;
}

/**
* @return array<\Spryker\Zed\FileManagerGuiExtension\Dependency\Plugin\FileInfoViewTableActionsExpanderPluginInterface>
*/
protected function getFileInfoViewTableActionsExpanderPlugins(): array
{
return [];
}
}

0 comments on commit 8f93e20

Please sign in to comment.