10000 [LiveComponent] AsLiveComponent attribute inheritance · Issue #2236 · symfony/ux · GitHub
[go: up one dir, main page]

Skip to content
[LiveComponent] AsLiveComponent attribute inheritance #2236
Open
@jannes-io

Description

@jannes-io

It would be great if AsLiveComponent could be extended to pre-fill certain values when working on Symfony bundles built on the shoulders of symfony/ux.

Real world use-case:
I currently provide a DataTable driven by LiveComponent in one of my bundles. The bundle, and users of the bundle are currently required to use the AsLiveComponent attribute, like so:

#[AsLiveComponent('ItemTable', '@MyBundle/components/table/table.html.twig', csrf: false)]
class ItemTable extends DataTable
{
	// ...
}

This request would be so that "MyBundle" could provide an attribute, #[AsTable()], which would both fill params, and enforce certain values that are expected to be set that way by default. This would enable us to change the underlying default template location, routes, attributes,... without causing a backwards compatibility break for users of the bundle.

For example:

#[\Attribute(\Attribute::TARGET_CLASS)]
class AsTable extends AsLiveComponent
{
    public function __construct(
        ?string $name = null,
        ?string $template = '@MyBundle/components/table/table.html.twig',
    ) {
        parent::__construct($name, $template, null, true, 'attributes', false, 'ux_data_table', 'post', UrlGeneratorInterface::ABSOLUTE_PATH);
    }
}

#[AsTable('ItemTable')]
class ItemTable extends DataTable
{
	// ...
}

Work required:
Currently AsLiveComponent is marked final, so that would have to go.
Other than that, I have no clue what the implications could be for subscribers, dependency injection,... I assume these aren't built to deal with attribute class inheritance?

Metadata

Metadata

Assignees

No one assigned

    Labels

    LiveComponentRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0