Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I noticed that field machine names of custom fields are being output as "entity-id-*" instead of "field-name". For example, when I look at the view information of two similar views in 6 and 7, I see views-view-field--entity-id-1.tpl.php instead of views-view-field--title.tpl.php, and the same when I try theming them ($fields['entity_id_1'] instead of $fields['title']). I am wondering if there's a reason for that, but it seems like a bit of a regression.
Comment | File | Size | Author |
---|---|---|---|
#23 | 1024586-rename_fieldapi.patch | 8.52 KB | dawehner |
#21 | ghost-fields.png | 34.51 KB | blup |
#9 | 1024586-rename_fieldapi.patch | 10.56 KB | dawehner |
#3 | fieldname.patch | 779 bytes | blup |
Comments
Comment #1
dawehnerThe field has to be entity-id, because the data is configured as entity id.
The first one is adressed on #973698: Questions about template naming conventions
Comment #2
blup CreditAttribution: blup commentedSo if I have two similar views with the same fields (different parameters), but I happened to add them in a different order, I'd have to rewrite the tpl file to accommodate the different entity_id_#'s? Seems like a big step backwards for designers. Especially the lack of readability of the variables.
Comment #3
blup CreditAttribution: blup commentedWhy not do something like this? Apart from the error below (which appears and disappears), it seems to work well for me. I'd appreciate your feedback.
Comment #4
dawehnerThe problem with this patch is that it will break a lot of things.
a) revisions
b) all existing views
c) all existing d7 templates
d) more
I think we basically can't change this field name anymore without getting big problems.
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedSo here's the thing.
I agree that there is no reason to use entity_id here, and I'm a little startled to see that we have this hardcoded string in there as a field ID, especially considering that this string is used so heavily.
We have to fix this. I realize it's going to cause problems, but this can't stay like this. When you've got almost all entity fields in a view, then your tokens will be all entity_id, entity_id1, entity_id2 with no way to distinguish between them. When we've already got perfectly good IDs to use, and we're just not using them. :/
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedThis is the reason we're releasing alpha versions, btw. We recognize that we may have to fix major design flaws. This is one case we're I think we're better off fixing it and telling people that things are not going to upgrade cleanly.
Comment #7
rvilarsubscribing
Comment #8
tim.plunkettSubscribe.
Comment #9
dawehnerHere is a patch
* tests views_get_handler:
* test basic functionality
* test the moved to feature
* test override handler feature
* add "moved to" to fieldapi data:
* renamed entity_id to $field_name
* renamed revision_id to $field_name . 'revision_id', because that's the way to take sure of uniqueness.
The tests are working for
@merlinofchaos
had to be changed. There was a recursion check in this line which was a duplicate of the later recursion check
Comment #10
stBorchertMinor notes from quick review:
change to
Comment #11
blup CreditAttribution: blup commentedJust tested the above patch, and it seems to work fine. The only detail I noticed is that for each field_* row in the listing, I have a 'ghost' row: "Error: missing group: / Error: missing title / Error: missing help". Nevertheless, the fields work fine, and the 'Views information' is now correctly naming the field tpl suggestions (views-view-field--field-description.tpl.php instead of views-view-field--entity-id-2.tpl.php). One thing I didn't test, however, is making a tpl to check the vars are correct.
Comment #12
pitkane CreditAttribution: pitkane commentedSubscribe
Comment #13
davidcie CreditAttribution: davidcie commentedSubscribe.
Comment #14
big_smile CreditAttribution: big_smile commentedI am using this patch on my website:
http://premsat.co.uk/
(All the http://premsat.co.uk/taxonomy/term/ pages are Views with the patch)
The patch works fine, except I get the 'Ghost' row Blup mentioned.
I have used the patch with tpl.php files and everything is fine.
Please note: When you use the patch, you must re-create all your existing views in order for the entity id to be replaced with the actual field name.
Comment #15
AmiraL CreditAttribution: AmiraL commentedany of these topics anlamamhttp://www.ikinci-el.tk
Comment #16
dawehnerIf you really have to recreate the views this patch fails.
Comment #17
dawehner@big_smile
Did you cleared your views cache before trying out this.
admin/structure/views/tools is the url for this.
Comment #18
blup CreditAttribution: blup commented@dereine
I just tested making a simple view with node article fields, applied the patch, cleared views cache, and went to edit the view and it seems to work fine. Pre-patch fields are still named entity_id_x, but new fields are correctly named. They all show up as they should. This is what i have, for example, as tokens:
[entity_id] == Fields: body
[entity_id_1] == Fields: field_image
[entity_id_2] == Fields: field_tags
[field_long] == Fields: field_long <--- after patch
[field_long-value] == Raw value
[field_long-format] == Raw format
The ghost fields, however, remain there - one for each field.
Comment #19
big_smile CreditAttribution: big_smile commentedSorry. I didn't explain very well. You only have to re-create your view to make existing fields get the correct names. (After further experimentation, I have found that you can also just delete the fields old and re-insert them). All fields created after the patch have the correct names.
Sorry for not explaining too well. I hope I didn't cause any problems.
Comment #20
dawehnerCan someone post a screenshot of the "ghost fields"?
Comment #21
blup CreditAttribution: blup commentedHere you go. What i meant by ghost fields = equal number of 'Error: missing group: Error: missing title' fields for each working one. Maybe shadow fields was a better analogy? :)
Comment #22
interX CreditAttribution: interX commentedThe patch worked form me when adding a new field, but not for existing fields in views. I did clear the Views cache.
I had a view with an entity "entity_id_1" in it. After the patch this one remained unchanged. However, adding the same field again and it gets "field_image" as name/token.
# [entity_id_1] == Fields: field_image
# [field_image] == Fields: field_image
An upgrade path for any existing views with entities should be available as well.
I didn't see any ghost fields here.
Comment #23
dawehnerHere is a new version of the patch which fixes this.
Comment #24
tim.plunkettEverything checks out, except one small typo:
s/Take/Make
Still marking this as RTBC.
Comment #25
aspilicious CreditAttribution: aspilicious commentedshouldn't that be is created?
Comment #26
interX CreditAttribution: interX commentedPatch in #23 works for me, the UI now shows everything correctly.
One note : In the Views template you still get $fields['entity_id_1'] for the existing field and $fields['field_image'] for the new field. I do get this can't be changed anymore... I'm mentioning it because this can potentially break existing (prepatch) templates that print fields directly by key.
Comment #27
dawehnerThis is how it should work.
Why can this break prepatch templates? Just the new fields get's changed.
Comment #28
interX CreditAttribution: interX commentedImage this scenario :
I have a view with a field entity_id
I create a page display
I use a template views-view-fields--myview--page.tpl.php, i use print $fields['entity_id']
Views is updated to a version with patch
I add another page display (overridden fields) with the same field, it uses the same template suggestion
In that scenario print $fields['entity_id'] won't work for my 2nd page display, I have have to create a more specific template or add logic to check on both field names.
On 2nd thought, I rephrase my previous comment. It's not really breaking the existing view template, but the template won't be compatible with the new page display. I admit, it's an unusual scenario... maybe it can just be discarded :)
Comment #29
tim.plunkettI was under the assumption that anyone using hardcoded calls to 'entity_id' will have broken code, but that's not the responsibility of this patch.
Comment #30
dawehnerCommited to cvs and git.