Closed (fixed)
Project:
Entityreference prepopulate [D7]
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Jun 2013 at 14:23 UTC
Updated:
2 Jun 2022 at 11:49 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #1
duaelfrHere is the patch !
I added a few tests but feel free to improve them as I am not really good for it.
This patch is part of the #1day1patch initiative.
Comment #3
duaelfrI said I was not good at patches...
Comment #4
chipway commented#1: entityreference_prepopulate-add_action_option_value-2028735-1.patch queued for re-testing.
Comment #6
amitaibuCan you explain this part?
value => item
Comment #7
duaelfrThe first part removes the entity ID to only let its title (better for UX I think).
I don't understand your second comment, the key of my option is named 'value' to make reference to the form field type used to hide the field.
Comment #8
amitaibu> The first part removes the entity ID to only let its title (better for UX I think).
Can't we just use entity_label() form the entity ID instead?
Comment #9
duaelfrThe entity_id is extracted by entityreference with a regular expression so I think using regexp is ok.
If you think entity_label is lighter and more understandable than my method, I have no reason to refuse :)
Comment #10
roysegall commentedBasicly the test is ok expect for two things:
1. You try to verify that the field was replaced by the label but you weren't in the node edit/create form, so the text was not available.
2. You didn't verify in the test that the value option is applied on the edit of the node. I added this part in test.
Comment #11
amitaibuI suspect you test this only with autocomplete, and not with a select list (where we won't have the entity ID in brackets). So let's use entity_label().
Comment #12
duaelfrThank you Roy !
If I understand what you say in your first point, the previous test "Hide the field." cannot be valid because it is missing the
$this->drupalGet('node/add/' . $this->node1->type, $options);too.Here is a new patch to use entity_label instead of a regexp. I let you fix the "Hide the field" test in another issue.
Comment #14
duaelfrWhat happened ?
I don't understand why this patch didn't pass...
Comment #15
roysegall commentedI'm trying to figure now.
Comment #16
roysegall commentedAfter some investigation the correct way is:
Because when creating the entity the $id don't have a value. Any way, i think this is a bit messy.
Also, have you tried this feature with select list as @amitaibu mention before? With select list the the feature don't work because element_children($form[$field_name][$lang]) is returning nothing is the list will not be a markup but remains a select list.
Comment #17
amitaibuInstead of working with the form try calling entityreference_prepopulate_get_values()
Comment #18
duaelfr@Roy : I think $id is the edited entity id not the referenced entity id so I think I should not use it here.
I fully rewrited my function to use more
$idswhich is populated byentityreference_prepopulate_get_values()and to find something that will work for all widgets. I think that tests will continue to work as they only test the concept (*crossing fingers*).Comment #20
amitaibumaybe $tmp_entity => $entity_item ?
XSS! :) use check_plain()
In that case don't use #markup, use the #theme => 'item_list'
Comment #21
duaelfrDone !
Comment #23
duaelfrTests fixed (I hope)
Comment #24
roysegall commentedI'm attaching a minor fix the patch: i try to verify that when the widget type is select list and the user editing the entity the label of the entities should appear - that didn't occurred. When editing, the $ids variable does not holds the populated field values. I fixed that and verified that in the simple test.
Comment #25
roysegall commentedFixing typo.
Comment #26
amitaibuhas => have
We can just create a new element as assign to to $form[$field_name][$lang] -- instead of iterating and unsetting the existing element.
Comment #27
roysegall commentedremoving the unset is working for me but for the simple test can't handle it:
Comment #28
roysegall commentedComment #29
duaelfrI had styles issues without unsetting #theme on multiple fields.
You are overriding $form[$field_name][$lang] so the values will be lost on the form submission. This is the reason why I used $lang . '_label' as form field key.
Comment #30
roysegall commented@DuaelFr you'r right with you said. I don't know how the prepopulated save the value in the fields but i made a few changes.
Comment #31
amitaibuhas => have
Why not use $wrapper?
'und' should probably be $langcode?
XSS - make sure to use check_plain()
Comment #32
roysegall commentedComment #33
roysegall commentedComment #34
amitaibuno need for this, just do $ids = $wrapper->{$field_name}->value(array('identifier' => TRUE));
Comment #35
amitaibubtw, When would we have an $ids with values?
Comment #36
roysegall commentedWe have $ids when we in a URL like: node/add/article?field_node_ref=1
Comment #37
chris_h commentedI've been using this in production for nearly a year now and works great
Comment #38
jgullstr commentedAdded #2126203: new action type in prepopulate : Display rendered entity as related issue, as this behavior is possible to replicate using a display mode.
Comment #39
hbjosemaria commentedIf this works, why isn't it commited yet? Now I have to patch ERP :<
Comment #40
delacosta456 commentedhello ... hi please
for this issue , which patch can apply safely please ?
Comment #41
anybody#36 was committed to 7.x-1.x-dev! :) Thanks all!