-
Notifications
You must be signed in to change notification settings - Fork 2
PhpCode as a new Transformer #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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.
* @param array $arguments |
Copilot uses AI. Check for mistakes.
interface PhpCodeTransformerInterface | ||
{ | ||
/** | ||
* @param mixed $value |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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.
* @param mixed $value |
Copilot uses AI. Check for mistakes.
* @param mixed $value | ||
* @param array $arguments | ||
* | ||
* @return AdvancedValue[] |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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.
* @return AdvancedValue[] |
Copilot uses AI. Check for mistakes.
public function transform(array $value, array $config): array | ||
{ | ||
$phpClass = $config['phpClass'] ?? null; | ||
$arguments = $config['arguments'] ?? []; |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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'] ?? [];
$arguments = $config['arguments'] ?? []; | |
$arguments = $config['arguments'] ?? []; |
Copilot uses AI. Check for mistakes.
$results[] = new AdvancedValue( | ||
'string', | ||
$transformed[0] ?? null, | ||
$val->getFieldName() | ||
); |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
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.
$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.
There was a problem hiding this 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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
/** | ||
* @internal | ||
*/ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow this Naming Convention for loading TaggedIerator.
https://github.com/pimcore/studio-backend-bundle/tree/826a6d30eb37976b5f9d9fe0c961d5ffe0edf92d/src/Grid/Service/Loader
And also check if the right Interface is implemented in the Service.
https://github.com/pimcore/studio-backend-bundle/blob/e19035b117c060a5e78b6439dba8dd8be98b7a3e/src/DependencyInjection/CompilerPass/GridColumnCollectorPass.php
|
Changes in this pull request
Resolves #1155
Additional info