Closed (fixed)
Project:
Edit
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
5 Jul 2012 at 10:05 UTC
Updated:
26 Jul 2012 at 07:41 UTC
Jump to comment: Most recent file
In order to make it work with Omega-based themes, I had to change
$var['title_attributes_array']['class'] = 'edit-pseudofield edit-field edit-allowed edit-type-direct';
to
$var['title_attributes_array']['class'] = array('edit-pseudofield', 'edit-field', 'edit-allowed', 'edit-type-direct');
I don't know if it's an Edit bug, or Omega bug, but since classes should always be arrays, I think I'm posting this bug in the right place…
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | edit-classes-strings-to-array-1672248-2.patch | 5.25 KB | psynaptic |
| #23 | edit-var-to-variables-1672248-2.patch | 5.58 KB | psynaptic |
| #15 | edit-classes-strings-to-array-1672248.patch | 4.79 KB | psynaptic |
| #13 | edit-var-to-variables-1672248.patch | 5.56 KB | psynaptic |
| #9 | editclasses-1672248-9.patch | 7.04 KB | jdanthinne |
Comments
Comment #1
wim leersThanks for the bug report! You're most likely posting in the right place :) If anything breaks with the Edit module installed, assume it's Edit module's fault — it's in alpha stage after all!
Please confirm that this works as well:
$var['title_attributes_array']['class'][] = 'edit-pseudofield edit-field edit-allowed edit-type-direct';That should *add* Edit module's attributes, instead of overriding them, like in my original code and like in your proposed change.
Comment #2
jdanthinne commentedThe perfect thing would then be:
$var['title_attributes_array']['class'] = array_merge($var['title_attributes_array']['class'], array('edit-pseudofield', 'edit-field', 'edit-allowed', 'edit-type-direct'));Like that, we deal only with regular arrays, not a mix of strings and arrays.
Note that the same thing is also present in the edit_node_wrap_name and edit_node_wrap_date functions. I didn't have to change that to make it work with Omega, but I don't know if the function is working as it should be as well…
Comment #3
wim leersI disagree. That's just overkill.
The way I proposed is also how e.g. Bartik does it:
$variables['title_attributes_array']['class'][] = 'element-invisible';If this fixes the problem, I'll commit this ASAP. Please set to RTBC if it solves your problem :)
Regarding
edit_node_wrap_(name|date): not doing it the way I currently do it implies that I have to pass an array into the theme function. Which means I have to doimplode(' ', $var['classes'])in the theme function, which is bad. We don't want any logic in theme functions :)Comment #4
jdanthinne commentedAll right, I'm too strict :-) Your way is right as well, and working, so RTBC!
Comment #5
psynaptic commentedRe: #3
I disagree that this should be a string of space-separated classes.
If this was a template file then
template_processwould convert the classes array into a string viadrupal_attributes. I don't see the problem of using the same technique in a theme function.For one thing, if someone wanted to adjust the classes they would need to work with the compound string, rather than an array.
Many (most?) theme functions use
drupal_attributesfor this very purpose. For example:http://api.drupal.org/api/drupal/includes%21form.inc/function/theme_date/7
http://api.drupal.org/api/drupal/includes%21form.inc/function/theme_butt...
http://api.drupal.org/api/drupal/includes%21form.inc/function/theme_fiel...
In fact, looking at the code more closely,
edit_preprocess_pagedoes usedrupal_attributesbecause it is creating a wrapper for the title usingtitle_prefixandtitle_suffix. The code inedit_preprocess_nodedoesn't usedrupal_attributesbecause array to string conversion is handled intemplate_process.Either way, we really do need to using arrays for classes.
I also think we should be using
$variables, rather than$varas it is more standard and readable.I'm happy to create a patch if you agree with my comments.
Comment #6
wim leersYou're absolutely right. I forgot about
drupal_attributes()for a minute.So then the classes defined in
edit_preprocess_page()would need to be converted to use an array as well, right?I also see your point about
$varvs.$variables. I did that deliberately because I think it's too verbose and didn't feel like typing it so often back when this was still experimental code. I'm fine with converting this to Drupal core's conventions, but please do that in a separate issue/patch :)So: yes, I agree with your comments, and greatly appreciate your offer for a patch! :) Unassigning myself. Thank you!
Comment #7
psynaptic commentedThanks, Wim.
I'm working on cleaning up the documentation right now. I will work on the two above mentioned issues as separate patches once I have submitted the one I am working on now.
Comment #8
wim leersThat's so awesome! :D Thanks :)
Comment #9
jdanthinne commentedHad some time to do the patch…
Converted classes strings to arrays, and $var to $variables.
Comment #10
psynaptic commentedI wonder whether we should use this format instead of
array_merge:This way, we can document each class if we want to and it avoids the slightly less readable
array_mergesyntax.Comment #11
psynaptic commentedFuller review:
We should be using
!empty($variables['node'])instead ofarray_keys_exist.We don't need the space after
divasdrupal_attributesoutputs that for us. We don't need the double quote either.We shouldn't use shorthand variable names like
$i.$entity_infowould be much more descriptive.As mentioned in my above comment, I would prefer these to use the
$variables['classes_array'][] = 'edit-entity';syntax.This check can be avoided if we use the other syntax.
I much prefer
if (empty($variables['attributes_array'])) { ...but it could be avoided altogether if using the other syntax for appending to the array.The comma is in the wrong position in this line, but this will be gone if we switch to the array append syntax.
There is an unwanted newline here.
As discussed, this should use
drupal_attributes, rather thanimplode.Comment #12
psynaptic commentedLet me know if you'd rather I picked up these issues. I'm keen to get on with it but don't want to step on your toes.
Comment #13
psynaptic commentedI have split the
$variableschanges out into a separate patch. This patch does the following:$varto$variablesthroughout the module.array_key_existscalls to useemptyinstead. This is recommended when you don't need to check for keys that may contain a value ofNULL.divand beforedrupal_attributesinedit_preprocess_pageasdrupal_attributesadds this for us. Also, removed a stray double quote from this line.Comment #14
psynaptic commented@Wim: are you going to be around on IRC today? I would love to have a chat with you about this.
Comment #15
psynaptic commentedThis next patch deals with the original issue, that of the classes being strings rather than arrays.
Here is what I did:
theme_edit_spanned_fieldto use attributes array instead of the custom classes array. This brings it inline with core and allows us to put thedata-attributes in there too, instead of concatenating strings as we were doing before.data-attributes to the attributes array intheme_edit_spanned_fieldinstead of concatenating strings together.theme_edit_spanned_fieldto be more core-like.This patch is stacked on top of the one in #13 for easier code review.
Comment #16
jdanthinne commentedBoth patch #13 and #15 working fine for me!
Comment #17
wim leers@psynaptic: I'm afraid not, I've ATM been calling >4 hours straight, it's almost 10 PM and I still haven't had dinner! Please shoot me an e-mail instead, if you want a reply by tomorrow.
(I can't be online tomorrow either, I'm having my graduation ceremony tomorrow afternoon, and I doubt you'll be online before noon in my timezone — which is Europe.)
Will look at these comments & patches tomorrow — thanks guys! :)
Comment #18
psynaptic commentedThanks for the replies guys.
I'm actually in the UK, which last I checked was in Europe. ;)
I'll likely be online tomorrow looking to press forward with more on this. I'll keep my eye on my dashboard and look forward to speaking with you tomorrow.
Comment #19
wim leersComment #20
wim leers#13
Won't this trigger a notice in case
$variables['node']does not exist?Nice clean-up, my ignorant mind didn't know about this :) Thanks!
#15
This line, plus the identical one in
edit_node_wrap_date()are a left-over from how it was written previously. This is a good clean-up :)If you could answer/possibly solve the question for #13, I'd be happy to commit both patches. I'd already commit #15, but it depends on #13, so :)
Comment #21
wim leersImproved issue title.
Comment #22
psynaptic commentedNo, this is the point of using empty. It checks if the property is set and ensures a non-empty value.
From the PHP manual:
Comment #23
psynaptic commentedHere is a re-roll of #13 as the other one doesn't apply any longer.
Comment #24
psynaptic commentedHere's a re-roll of #15 too, as it doesn't apply any longer.
Comment #25
psynaptic commented@Wim: I didn't seem to get any attribution for my work in #1672598: Clean up inline code documentation in PHP files. I think that is because you edited my changes and didn't commit my patch directly using the workflow described in Adding a commit author. Would it be possible for you to please pass back any change requests to me so we can discuss the merits of each item and so that I may correct them myself? That way my patches can be committed directly and I'll get the attribution.
Comment #26
psynaptic commentedOn a side note, I have added edit, fape, and every_field modules to drupalcontrib.org so we can get reference docs while we work. Cron needs to run but it shouldn't take long before they show up.
Comment #27
wim leers#22: Okay, thanks. Goddamn PHP mess: isset()/empty()/array_key_exists()…
#23/#24: I'll commit this tomorrow — thanks :)
#25: Actually I *did* give you attribution :) Please see http://drupalcode.org/project/edit.git/commit/8238c54 and http://drupal.org/node/1649212/committers :) AFAICT everything looks good?
#26: awesome :)
Comment #28
psynaptic commented#25: Wow, sorry about that. I was looking at spark for some stupid reason!
Comment #29
wim leersCommitted #23 & #24: http://drupalcode.org/project/edit.git/commit/06c4e96, http://drupalcode.org/project/edit.git/commit/70427a0.
Comment #30
resveld commentedI can confirm the patch is applied and works fine!
Comment #31
wim leersExcellent, thanks for testing resveld! :) If you have other feedback, feel free to create a new issue! :)
Comment #32
resveld commentedalready done! ;)