Skip to content

Proposal: Ability to specify identifier property of custom item operations#2126

Closed
soyuka wants to merge 1 commit into
api-platform:masterfrom
soyuka:easier-custom-operations
Closed

Proposal: Ability to specify identifier property of custom item operations#2126
soyuka wants to merge 1 commit into
api-platform:masterfrom
soyuka:easier-custom-operations

Conversation

@soyuka

@soyuka soyuka commented Jul 25, 2018

Copy link
Copy Markdown
Member
Q A
Bug fix? not really
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? (need to add tests)
Fixed tickets #2116
License MIT
Doc PR todo

When declaring a custom item operation, you often want to use another property as identifier, for example:

<?php
/**
 * @ApiResource(itemOperations={
 *     "get",
 *     "put",
 *     "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}}
 * })
 */
class Book {}

Today, this only works if you add a custom controller, either by using your own data or by calling the core data provider with new identifiers ['isbn' => 1].

My proposal is to add a property in the operation route defaults:

<?php
/*
 * @ApiResource(itemOperations={
 *     "get",
 *     "put",
 *     "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}, "defaults"={"identifiedBy"="isbn"}}
 * })
 */
class Book {}

By using this you have nothing else to add (no controller, no data provider), it'll just use the isbn property as identifier.

This is a WIP, to be done:

  • accept proposal
  • add tests

@soyuka soyuka changed the title WIP: Ability to specify identifier property of custom item operations Proposal: Ability to specify identifier property of custom item operations Feb 15, 2019
@ziiko10

ziiko10 commented Nov 18, 2019

Copy link
Copy Markdown

Hello
I want to use custom identifier in a custom action without using {id} like this .

 @ApiResource(
   itemOperations={
     "FORGOT-PASSWORD"={
      "method"="PUT",
      "path"="/users/{forgotPasswordToken}/forgot-password",
      "controller"="App\Controller\ForgotPasswordController",
      "defaults"={"identifiedBy"="forgotPasswordToken"}
      }
    }
  )

But i still have the same error with "Invalid identifier value or configuration" .

Any issue please ?

@teohhanhui

Copy link
Copy Markdown
Contributor

This should probably not be in the route defaults.

@teohhanhui

Copy link
Copy Markdown
Contributor

@AbbesBendaoud10 It's not implemented yet.

@soyuka

soyuka commented Nov 21, 2019

Copy link
Copy Markdown
Member Author

This should probably not be in the route defaults.

👍 should be a new attribute

@hafkenscheid

Copy link
Copy Markdown

Any news regarding this?

@soyuka soyuka force-pushed the easier-custom-operations branch from e006023 to 2010727 Compare July 27, 2020 19:29
@lamb0tiana

Copy link
Copy Markdown

@soyuka @AbbesBendaoud10 how did you resolved that, I spent 2 days but nothing, would you help please, thank you.

@ziiko10

ziiko10 commented Aug 6, 2020

Copy link
Copy Markdown

@lamb0tiana i did it with "_api_receive"=false.

@soyuka

soyuka commented Aug 7, 2020

Copy link
Copy Markdown
Member Author

Use a custom route with a custom controller / data provider.

@souhaiboutoure

Copy link
Copy Markdown

@lamb0tiana i did it with "_api_receive"=false.

@AbbesBendaoud10 Thanks it worked for me 🥇

@soyuka

soyuka commented Oct 20, 2020

Copy link
Copy Markdown
Member Author

#3664

@soyuka soyuka closed this Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants