Skip to content
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

Fixed event data passing example #1829

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/LiveComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2728,18 +2728,18 @@ You can also pass extra (scalar) data to the listeners::
// ...

$this->emit('productAdded', [
'product' => $product->getId(),
'productId' => $product->getId(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

That will make the Product entity example (L2745-2752) not working :|

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you keep the "product" var name and fix the $data[...] you spotted ? :)

]);
}

In your listeners, you can access this by adding a matching argument
name with ``#[LiveArg]`` in front::

#[LiveListener('productAdded')]
public function incrementProductCount(#[LiveArg] int $product)
public function incrementProductCount(#[LiveArg] int $productId)
{
$this->productCount++;
$this->lastProduct = $data['product'];
$this->lastProductId = $productId;
}

And because event listeners are also actions, you can type-hint an argument
Expand Down