How to create buttontransfer entity while using CustomerTableActionExpanderPluginInterface?

jsinha
jsinha Posts: 16 🧑🏻‍🚀 - Cadet

Hi team!
I am working on spryker plugin where I am using CustomerTableActionExpanderPluginInterface
to adding the button in table view into the backoffice,

public function execute(int $idCustomer, array $buttonTransfers): array{

// hre the buttontransfer getting expanded into the Communication/Table/SomeTable::class
// But I am not able to define the button entity.
return $buttonTransfers;
}
all are going fine, but there is only one issue;
Not able to define the button value.
Please help me.
Thanks!

Best Answers

  • amansilla
    amansilla Sprykee Posts: 20 🪐 - Explorer
    edited October 2023 Answer ✓
    • Hi @jsinha,

      I'm not sure what you exactly mean by the button value, I guess you probably mean the URL used whenever the user clicks on the button. If that is the case it may look something like this.
    use Generated\Shared\Transfer\ButtonTransfer;
    use Spryker\Service\UtilText\Model\Url\Url;

    public function execute(int $idCustomer, array $buttonTransfers): array
    {
    // first generate the URL $url = Url::generate( 'your-url/perform-some-action', [ // any additional parameter e.g. customerId 'customer-id' => $idCustomer, ], ); $buttons[] = (new ButtonTransfer()) ->setUrl($url) ->setTitle('Your button tittle') ->setDefaultOptions([
    // 'class' => 'here you can add any CSS class', // 'icon' => 'you can also define some icon',
    ]); return $buttonTransfers; }

    I hope this helps you find the specific solution you want.

    Let me know whether this helped, otherwise, maybe you can add some additional information about your specific use case so I can guide you. Cheers 😉

  • jsinha
    jsinha Posts: 16 🧑🏻‍🚀 - Cadet
    Answer ✓

    Hi @amansilla
    Thank you very much !!

Answers

  • amansilla
    amansilla Sprykee Posts: 20 🪐 - Explorer
    edited October 2023 Answer ✓
    • Hi @jsinha,

      I'm not sure what you exactly mean by the button value, I guess you probably mean the URL used whenever the user clicks on the button. If that is the case it may look something like this.
    use Generated\Shared\Transfer\ButtonTransfer;
    use Spryker\Service\UtilText\Model\Url\Url;

    public function execute(int $idCustomer, array $buttonTransfers): array
    {
    // first generate the URL $url = Url::generate( 'your-url/perform-some-action', [ // any additional parameter e.g. customerId 'customer-id' => $idCustomer, ], ); $buttons[] = (new ButtonTransfer()) ->setUrl($url) ->setTitle('Your button tittle') ->setDefaultOptions([
    // 'class' => 'here you can add any CSS class', // 'icon' => 'you can also define some icon',
    ]); return $buttonTransfers; }

    I hope this helps you find the specific solution you want.

    Let me know whether this helped, otherwise, maybe you can add some additional information about your specific use case so I can guide you. Cheers 😉

  • jsinha
    jsinha Posts: 16 🧑🏻‍🚀 - Cadet
    Answer ✓

    Hi @amansilla
    Thank you very much !!