Feature #44149

getIdentifierByObject for POP-Objects

Added by Benno Weinzierl almost 9 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
-- undefined --
Category:
Persistence
Target version:
-
Start date:
2012-12-20
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

PersistenceManager::getIdentifierByObject() currently returns NULL if you pass it a "non-entity", thus PersistenceManager::convertObjectToIdentityArray() throws an exception if the array contains such object.
This feature request suggests to make it possible to retrieve a unique id for arbitrary Plain Old PHP objects.

NOTE

I moved this issue from the Fluid tracker. It had the subject Usage of Session Scope Objects as arguments in f:link.action should be possible but is rather an "issue" of the persistence.
I'm not convinced that such feature would make sense yet, but I wanted to get some more input before rejecting it.

Here the original description:

When trying to use a session scope object as argument in f:link.action viewhelper i get the following Error:

#1302628242: The given object is unknown to the Persistence Manager.

It sould be possible to use Session Scope Obejcts (or objects stored inside them) as arguments because they are persisted in session scope.

Here is a example:
I have a ShopingBasket with scope=session with BasketItems stroed inside. Now i want to create a delete link for a BasketItem. This is not possible without using a self implemented id at the moment.

#1

Updated by Bastian Waidelich almost 9 years ago

  • Category set to ViewHelpers
  • Status changed from New to Needs Feedback
  • Assignee set to Bastian Waidelich

Objects that are not known to the Persistence Manager don't have an identifier. so how should we generate the link? Serializing the complete object is not an option.
Instead, you should inject the basket to your controller and have a deleteItemAction or similar.

Or did I get you wrong?

#2

Updated by Benno Weinzierl almost 9 years ago

Objects that are not known to the Persistence Manager don't have an identifier. so how should we generate the link? Serializing the complete object is not an option.

Yes, that's the problem. Why can't they have an identifier of some sort? They are persisted in the Session so there sould be an identifier?

Instead, you should inject the basket to your controller and have a deleteItemAction or similar.

Thats what i am trying to do. I have a deleteItemAction but i cannot send the item as an argument because it is persisted in the session and has therefore no identifier.

Or did I get you wrong?

#3

Updated by Bastian Waidelich almost 9 years ago

Benno Weinzierl wrote:

Objects that are not known to the Persistence Manager don't have an identifier. so how should we generate the link? Serializing the complete object is not an option.

Yes, that's the problem. Why can't they have an identifier of some sort? They are persisted in the Session so there sould be an identifier?

The scope "session" is a specialization of "singleton". It is meant for object instances to exist exactly once in the current session – like a shopping basket.
So there is no need to pass the object around, as well as there is no reason to pass around singletons – because you can always inject the object.

Instead, you should inject the basket to your controller and have a deleteItemAction or similar.

Thats what i am trying to do. I have a deleteItemAction but i cannot send the item as an argument because it is persisted in the session and has therefore no identifier.

Well, the item in your basket should have some relation to a persistent entity (e.g. product) don't they?
Maybe https://github.com/robertlemke/RoeBooks.Shop helps you (even though it's a bit outdated in the meantime).
Or how does an item in your basket look like?

#4

Updated by Benno Weinzierl almost 9 years ago

Bastian Waidelich wrote:

Benno Weinzierl wrote:

Objects that are not known to the Persistence Manager don't have an identifier. so how should we generate the link? Serializing the complete object is not an option.

Yes, that's the problem. Why can't they have an identifier of some sort? They are persisted in the Session so there sould be an identifier?

The scope "session" is a specialization of "singleton". It is meant for object instances to exist exactly once in the current session – like a shopping basket.
So there is no need to pass the object around, as well as there is no reason to pass around singletons – because you can always inject the object.

You got a point there for session objects. But what about any other prototype object possibly stroed inside a session scope object or maybe even a arbitrary prototype which i want to pass to the next controller. Would it not be great to just use any prototype object as argument?
Or at least if it is already stored in a sessionscope object? Likle my BasketItem?

Instead, you should inject the basket to your controller and have a deleteItemAction or similar.

Thats what i am trying to do. I have a deleteItemAction but i cannot send the item as an argument because it is persisted in the session and has therefore no identifier.

Well, the item in your basket should have some relation to a persistent entity (e.g. product) don't they?
Maybe https://github.com/robertlemke/RoeBooks.Shop helps you (even though it's a bit outdated in the meantime).
Or how does an item in your basket look like?

In my case the BasketItem hat property quantity, product but also configuration of the product. So in my case it is possible to put more than one basketItem with the same product in the basket. The only solution for my problem at the moment is to generate my own unique id for each item and sumbit that which is not realy flow-style.

#5

Updated by Bastian Waidelich almost 9 years ago

  • Project changed from TYPO3.Fluid to TYPO3.Flow
  • Category deleted (ViewHelpers)
#6

Updated by Bastian Waidelich almost 9 years ago

  • Subject changed from Usage of Session Scope Objects as arguments in f:link.action should be possible to getIdentifierByObject for POP-Objects
  • Category set to Persistence
  • Assignee deleted (Bastian Waidelich)
  • Priority changed from Should have to -- undefined --

Hi,

I moved this issue to the Flow tracker in order to get some more feedback, but I doubt that we should include such functionality to the core.

In my case the BasketItem hat property quantity, product but also configuration of the product.

You could simply pass the item index like:

<f:for each="{basket.items}" as="item" iteration="iteration">
  <f:link.action action="removeItem" arguments="{itemIndex: iteration.index}">Remove {item.title}</f:link.action>
</f:for>

Of course the index is ambiguous in this case – if you open the link twice it might remove two items from the basket. If that's an issue you can easily give the item it's own id (e.g. via \TYPO3\Flow\Utility\Algorithms::generateUUID()) and use it like:

<f:for each="{basket.items}" as="item">
  <f:link.action action="removeItem" arguments="{itemId: item.id}">Remove {item.title}</f:link.action>
</f:for>

HTH

#7

Updated by Karsten Dambekalns about 8 years ago

  • Status changed from Needs Feedback to Closed
  • Assignee set to Bastian Waidelich

Also available in: Atom PDF