Closed (fixed)
Project:
Weight
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
5 Oct 2012 at 00:02 UTC
Updated:
31 Oct 2014 at 19:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
davisbenUnfortunately I don't think this is possible. In looking at Search API, it appears to use entity properties and fields, or which the weight is neither.
Comment #2
muschpusch commentedActually this is a valid feature request :) I changed the title since supporting entity API should fix: rules, search api, restws (etc) integration. Please review and test the attached patch i only tested with restws
Comment #3
muschpusch commentedOk there was a problem when creating a node using entity API. See the updated patch for a fix
Comment #4
muschpusch commentedI'm actually not sure if it's safe what i'm doing in the last patch. Created an issue in the entity API queue: #2202379: make NID available in setter callback
Comment #5
joachim commentedD.org ate my last comment.
Briefly:
- the hook can go in a .inc file.
- you should not be saving the entity when the property is being set. That is not how wrappers are meant to work.
Comment #6
joachim commentedTo expand on that:
You should just be setting your data on the $data, which is the node.
If the user of the wrapper wants to save the node afterwards, they will do so.
At that point, hook_node_insert/update() is invoked, and your implementations of that will deal with saving your data to your table.
Comment #7
muschpusch commentedThanks a lot joachim! New patch attached.
Comment #8
joachim commentedThis isn't quite right yet.
You need to set the data on the $node in all circumstances.
You should not be saving the node yourself -- or your own data -- in any circumstance.
Comment #9
muschpusch commentedHey Joachim, _weight_set_weight($data); actually only saves in the custom weight table.
I do that
I don't do that anymore
How else should i tell entity API to save the value ?!?
Comment #10
joachim commented> Hey Joachim, _weight_set_weight($data); actually only saves in the custom weight table.
You should not be saving anything at all to the DB in response to a property being set. That's not the job of the setter.
You should change the $node in some way, for your implementation of hook_node_insert/update() to notice and deal with when the user chooses to save the node.
> How else should i tell entity API to save the value ?!?
Not the job of the setter callback. It's the responsibility of the user of the entity wrapper to save the node themselves.
Comment #11
muschpusch commentedQuit busy right now but will work on this end of the week...
Comment #12
megachrizThe attached patch addresses the issues noted in #8. I also removed whitespace, renamed the setter and getter callbacks and renamed the first parameter from the setter callback (
$data) to$nodeto be consistent with the getter callback.Comment #13
megachrizJust noticed that function docs for
weight_entity_property_info_alter()are not right. This should beImplements hook_entity_property_info_alter()instead ofImplements hook_entity_property_info().New patch.
Comment #14
deggertsen commentedPatch #13 worked great for me. I'm now able to use the weight field in my Search API index. Thanks!
Comment #15
mglamanMarking as RTBC based on #14!
Comment #16
argiepiano commentedThank you for the patch. In addition, with this patch, the Weight field of a node is now exposed to Rules and therefore can be set and changed.
Comment #17
davisbenCommitted. Thanks for the patch!