Skip to content

Conversation

stunnerparas
Copy link
Contributor

@stunnerparas stunnerparas commented Oct 20, 2025

Changes in this pull request

Resolves #1155

Additional info

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new PhpCode transformer system that allows developers to create custom PHP-based transformers for grid column values. The implementation uses Symfony's tagged service pattern to enable pluggable transformation logic.

Key changes:

  • Adds a new PhpCode transformer with a resolver pattern for discovering and executing tagged PHP transformer services
  • Provides an example transformer (ExamplePhpCodeTransformer) that converts strings to uppercase
  • Updates configuration and documentation to support the new transformer type

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Grid/Column/Transformer/PhpCode/TaggedPhpCodeTransformerResolver.php Implements the resolver to locate transformer services by class name using Symfony's TaggedIterator
src/Grid/Column/Transformer/PhpCode/PhpCodeTransformerResolverInterface.php Defines the contract for resolving PhpCode transformers with service tag constant
src/Grid/Column/Transformer/PhpCode/PhpCodeTransformerInterface.php Defines the contract that custom PHP transformers must implement
src/Grid/Column/Transformer/PhpCode/ExamplePhpCodeTransformer.php Provides a demonstration transformer that converts string values to uppercase
src/Grid/Column/Transformer/PhpCode.php Main transformer class that delegates to tagged services based on configuration
doc/03_Grid.md Adds documentation for the PhpCode transformer with usage examples
config/grid.yaml Registers the PhpCode transformer and example transformer as tagged services

{
/**
* @param mixed $value
* @param array $arguments
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the @param array $arguments annotation. The array type is already declared in the method signature, making this annotation redundant according to the coding guidelines.

Suggested change
* @param array $arguments

Copilot uses AI. Check for mistakes.

interface PhpCodeTransformerInterface
{
/**
* @param mixed $value
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the @param mixed $value annotation. The mixed type is already declared in the method signature, making this annotation redundant according to the coding guidelines.

Suggested change
* @param mixed $value

Copilot uses AI. Check for mistakes.

* @param mixed $value
* @param array $arguments
*
* @return AdvancedValue[]
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the @return AdvancedValue[] annotation. The return type array is already declared in the method signature. If more specificity about the array contents is needed, consider using a typed return such as a collection class, otherwise the annotation is redundant.

Suggested change
* @return AdvancedValue[]

Copilot uses AI. Check for mistakes.

public function transform(array $value, array $config): array
{
$phpClass = $config['phpClass'] ?? null;
$arguments = $config['arguments'] ?? [];
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra spaces around the assignment operator. Use single spaces: $phpClass = $config['phpClass'] ?? null; and $arguments = $config['arguments'] ?? [];

Suggested change
$arguments = $config['arguments'] ?? [];
$arguments = $config['arguments'] ?? [];

Copilot uses AI. Check for mistakes.

Comment on lines 63 to 67
$results[] = new AdvancedValue(
'string',
$transformed[0] ?? null,
$val->getFieldName()
);
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing only the first element $transformed[0] from the transformer's result array discards any additional transformed values. Consider documenting why only the first element is used or handling multiple values if the transformer returns more than one.

Suggested change
$results[] = new AdvancedValue(
'string',
$transformed[0] ?? null,
$val->getFieldName()
);
// Handle all transformed values, not just the first
foreach ($transformed as $t) {
$results[] = new AdvancedValue(
'string',
$t,
$val->getFieldName()
);
}

Copilot uses AI. Check for mistakes.

@martineiber martineiber added this to the next milestone Oct 20, 2025
@pimcore pimcore deleted a comment from Copilot AI Oct 20, 2025
@pimcore pimcore deleted a comment from Copilot AI Oct 20, 2025
Copy link
Contributor

@martineiber martineiber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes.

And the API Endpoint for listing the Tagged Services is still missing.

config/grid.yaml Outdated
#
# Example Transformer
#
Pimcore\Bundle\StudioBackendBundle\Grid\Column\Transformer\PhpCode\ExamplePhpCodeTransformer:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need a Example Service.

doc/03_Grid.md Outdated
**Available Configurations:**

- `phpClass`: The fully qualified class name of the transformer to execute. Must implement PhpCodeTransformerInterface.
- `arguments`: A key-value map of arguments passed to the transformer. These can be used to customize the transformation logic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need arguments we just want to call the Service. It should be possible to just implement a Service without adopting the Frontend. If that is needed we can implement a custom Transformer there we can set the "config"


#### PhpCode Transformer

The `PhpCode` transformer delegates value transformation to a custom PHP class implementing the PhpCodeTransformerInterface. This allows developers to encapsulate complex transformation logic in reusable services. You can specify the class to use via its fully qualified name (phpClass) and pass custom arguments to control its behavior. This is ideal for advanced use cases where transformation logic depends on external services, dynamic configuration, or custom business rules.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link the Interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. if it's registered as a service and tagged appropriately.

$transformer = $this->resolver->resolve($phpClass);

$results = [];
foreach ($value as $val) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not loop over the Values pass it directly to the Service.

Comment on lines 19 to 21
/**
* @internal
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be internal.

/**
* @internal
*/
final readonly class TaggedPhpCodeTransformerResolver implements PhpCodeTransformerResolverInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martineiber martineiber modified the milestones: 0.10.21, next Oct 21, 2025
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Grid] [Advanced Columns] Add Transformers

2 participants