소스 정보
- 저장소
- Guiziweb/guiziweb-plugins
- 최근 소스 활동
- 2026년 4월 16일 20:06
- 감지된 SKILL.md 언어
- 영어
- 스타
- 4
- 포크
- 0
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/Guiziweb/guiziweb-plugins --skill add-grid-export명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
Add an admin autocomplete form type for a Sylius Resource (translatable or not), optionally injected into another form via an extension
Add an admin FormType for an existing Sylius Resource
Add a Sylius admin grid for an existing Sylius Resource
SOC 직업 분류 기준
SKILL.md 표시 중
| name | add-grid-export |
| description | Add a CSV export button to an existing admin grid. |
| argument-hint | [ModelName] |
| allowed-tools | AskUserQuestion, Bash, Read, Edit, Write, Glob, Grep |
Ask the user for the ModelName if not provided.
Prerequisite: The resource, its grid and an
Indexoperation must already exist. Run/sylius-stack:add-resource,/sylius-stack:add-gridthen/sylius-stack:add-operation Indexfirst if needed.
composer require league/csv
Create src/Responder/ExportGridToCsvResponder.php:
<?php
declare(strict_types=1);
namespace App\Responder;
use League\Csv\Writer;
use Pagerfanta\PagerfantaInterface;
use Sylius\Component\Grid\Definition\Field;
use Sylius\Component\Grid\Renderer\GridRendererInterface;
use Sylius\Component\Grid\View\GridViewInterface;
use Sylius\Resource\Context\Context;
use Sylius\Resource\Metadata\Operation;
use Sylius\Resource\State\ResponderInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
use Webmozart\Assert\Assert;
final readonly class ExportGridToCsvResponder implements ResponderInterface
{
public function __construct(
#[Autowire(service: 'sylius.grid.renderer')]
private GridRendererInterface $gridRenderer,
private TranslatorInterface $translator,
) {
}
/**
* @param GridViewInterface $data
*/
public function respond(mixed $data, Operation $operation, Context $context): mixed
{
Assert::isInstanceOf($data, GridViewInterface::class);
$response = new StreamedResponse(function () use ($data) {
$output = fopen('php://output', 'w');
if (false === $output) {
throw new \RuntimeException('Unable to open output stream.');
}
$writer = Writer::from($output);
$fields = $this->sortFields($data->getDefinition()->getFields());
$this->writeHeaders($writer, $fields);
$this->writeRows($writer, $fields, $data);
});
$response->headers->set('Content-Type', 'text/csv; charset=UTF-8');
$response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
return $response;
}
/**
* @param Field[] $fields
*/
private function writeHeaders(Writer $writer, array $fields): void
{
$labels = array_map(fn (Field $field) => $this->translator->trans($field->getLabel()), $fields);
$writer->insertOne($labels);
}
/**
* @param Field[] $fields
*/
private function writeRows(Writer $writer, array $fields, GridViewInterface $gridView): void
{
/** @var PagerfantaInterface $paginator */
$paginator = $gridView->getData();
Assert::isInstanceOf($paginator, PagerfantaInterface::class);
for ($currentPage = 1; $currentPage <= $paginator->getNbPages(); ++$currentPage) {
$paginator->setCurrentPage($currentPage);
$this->writePageResults($writer, $fields, $gridView, $paginator->getCurrentPageResults());
}
}
/**
* @param Field[] $fields
* @param iterable<object> $pageResults
*/
private function writePageResults(Writer $writer, array $fields, GridViewInterface $gridView, iterable $pageResults): void
{
foreach ($pageResults as $resource) {
$rows = [];
foreach ($fields as $field) {
$rows[] = $this->getFieldValue($gridView, $field, $resource);
}
$writer->insertOne($rows);
}
}
private function getFieldValue(GridViewInterface $gridView, Field $field, object $data): string
{
$renderedData = $this->gridRenderer->renderField($gridView, $field, $data);
$renderedData = str_replace(\PHP_EOL, '', $renderedData);
return trim(strip_tags($renderedData));
}
/**
* @param Field[] $fields
*
* @return Field[]
*/
private function sortFields(array $fields): array
{
$sortedFields = $fields;
uasort($sortedFields, fn (Field $fieldA, Field $fieldB) => $fieldA->getPosition() <=> $fieldB->getPosition());
return $sortedFields;
}
}
Edit src/Entity/{ModelName}.php — keep the existing Index operation and add a second one with shortName: 'export' and the responder:
use App\Responder\ExportGridToCsvResponder;
// in the operations array:
new Index(
grid: Admin{ModelName}Grid::class,
),
new Index(
shortName: 'export',
responder: ExportGridToCsvResponder::class,
grid: Admin{ModelName}Grid::class,
),
See /sylius-stack:add-operation for the general mechanism of adding operations to a resource.
Edit src/Grid/Admin{ModelName}Grid.php — add the export action in MainActionGroup:
use Sylius\Bundle\GridBundle\Builder\Action\Action;
// in MainActionGroup:
MainActionGroup::create(
CreateAction::create(),
Action::create('export', 'export')
->setTemplate('shared/grid/action/export.html.twig'),
)
Create templates/shared/grid/action/export.html.twig:
{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('export')), options.link.parameters|default([]))) %}
{% set message = action.label %}
{% if message is empty %}
{% set message = 'app.ui.export' %}
{% endif %}
<a href="{{ path }}?{{ app.request.query.all()|url_encode }}" class="btn">
{{ ux_icon(action.icon|default('iwwa:csv'), {class: 'icon dropdown-item-icon'}) }}
{{ message|trans }}
</a>
Note: To avoid repeating
->setTemplate(...)in every grid, you can configure the template globally instead:# config/packages/sylius_grid.yaml sylius_grid: templates: action: export: 'shared/grid/action/export.html.twig'If you add this global config, remove the
->setTemplate(...)call from the grid.
Create or update translations/messages.en.yaml:
app:
ui:
export: 'Export'
bin/console cache:clear
bin/console debug:router app_admin_{model_snake}_export
bin/console sylius:debug:resource 'App\Entity\{ModelName}'
The route should exist and the resource metadata should list two Index operations (one default, one with shortName: 'export').