Attached patch:

  • Converts the archive module form to the fapi model.
  • Adds 'No posts found.' message if no posts are available. Perhaps the two instances of the status message can be combined together, but I've left if as it is for the moment. I think it'd be useful if the search module had a 'search by date' facility that the archive module could refer to at this point.
  • Adds some styling to provide a margin to both the form and the error message.
  • Removes unused variable $original from archive_calendar
  • Removes the section of code from archive_calendar that uses year, month and day in $_POST information as input. I don't see what the point of this is and don't believe it's used by any other module either.. Rather odd..
  • Moves hook_menu up.

That's about it.

Please review. Thanks :)

-K

CommentFileSizeAuthor
#9 archive_3.patch7.12 KBZen
#8 archive_2.patch7.12 KBZen
#6 eall.php.txt294 bytesZen
archive_1.patch7.1 KBZen
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dries’s picture

This is likely to generate warnings. You have to put quotes around string values:

+function archive_browse_form_submit($form_id, $form_values) {
+  return "archive/$form_values[year]/$form_values[month]/$form_values[day]";
+}
Zen’s picture

That's the original code untouched and I think it's correct - quotes shouldn't be used around associative array keys when inside a double quoted string. Or if you want to use them then the variable should be inside curly brackets (IIRC anyways).

-K

Zen’s picture

Couldn't find an exact reference to this on php.net , but you can see an example on phpdig.net : http://www.phpdig.net/ref/rn03.html [third snippet from the top].

Thanks.
-K

chx’s picture

archive/$form_values[year]/$form_values[month]/$form_values[day] incorrect.
'archive/' . $form_values['year'] etc. if php docs says otherwise, then those examples are sloppy code. flip on E_ALL and watch for yourself.

It's the original code? So what?

Zen’s picture

chx: It doesn't apply within a double-quoted string is what I'm saying. Array keys need to be quoted everywhere else except inside a double quoted string.

"It's the original code? So what?" - So we would have possibly encountered this before?

I'll test this shortly..
-K

Zen’s picture

FileSize
294 bytes

Please check the attached test script.

-K

Crell’s picture

Drupal's the only code I write these days not under E_ALL. :-)

I've not heard of echo "$form[a]" working before. It may, but it's ugly and unclear.

Personally, I always use {} if I'm putting a variable inside a double-quoted string. It's not always necessary but a good habit to get into, because it often is, especially when you're dealing with arrays so often.

So the correct way to do that function, IMHO, would be:

+function archive_browse_form_submit($form_id, $form_values) {
+ return "archive/{$form_values['year']}/{$form_values['month']}/{$form_values['day']}";
+}

It's E_ALL compliant, it's readable, it's a common style.

Zen’s picture

FileSize
7.12 KB

OK we're splitting hairs here now. Patch 1 attached.

-K
P.S And I hate curly braces as they are ugly and unclear ;)

Zen’s picture

FileSize
7.12 KB
Zen’s picture

http://us2.php.net/language.types.array <-- It clearly states here that "$form[year]" is perfectly valid. So, please use patch number 1.

Thanks
-K

Zen’s picture

Filter ate the rest of my message:

The above php.net link clearly states that using "$form[year]" is perfectly valid and acceptable. So please use patch no. 1.

Thanks
-K

chx’s picture

Is this some form of stupidity contest?

Again. Slowly. Drupal uses

'archive/'. $form['year']. '....

what's in this that can not be understood? There is a string constant, a concatenation operator, a variable and so on. String constants -- even if they happen to be in array indexes -- are to be put in single quotes. You have more than 30K LoC to learn all this.

Zen’s picture

I don't particularly care.. I'm fine with all three versions of this patch. Dries and yourself (chx) said that this would cause an error with E_ALL.. I've supplied PHP documentation and a test script that shows it doesn't and I've also supplied alternate versions of the patch to satisfy all parties. Nothing more that I can do.

And for the record, the syntax that appears to have gotten under chx's skin is used elsewhere in core as well.. Finding it and patching it.. I leave to chx as an exercise :)

-K

chx’s picture

you say that there is a $foo[something] in core? without quotes around the constant?? aggregator maybe :) but even there it should not be.

Dries’s picture

Status: Needs review » Fixed

Committed! Great job, Zen! Thanks.

Zen’s picture

Status: Fixed » Closed (fixed)