Today, the "Submitted by X, on xx/xx/xx" is generated by the theme function theme_node_submitted(). This theme function glue the username and date variable inside a single sentence.

Advanced themers easily know how to override this function but for the average themers it may be very difficult for them to change how authorname and submitted date are presented.

Furthermore, I think that there are many case where authorname and submitted date are not on the same line. For example one may want to put the author name at the end while the submitted date stays at the top of a node.

This is why I propose that we make available the two variables to the node template. Instead of $submitted, we should make available $submitted_date and $author. Therefore even beginners would be able to change how the datas are presented by changing the markup inside node.tpl.php.

This would be done by :

1) Cancelling the theme_node_submitted() function
2) Adding two lines in template_preprocess_node
* One to create the $author variable (if theme settings OK)
* One to create the $submitted_date variable (if theme settings OK)
3) Change the node.tpl.php with a new markup that print "Submitted by $author on $submitted_date"
4) Change node.tpl.php in other core themes

If someone tells me it is not a bad idea I could try to do the patch.

Files: 
CommentFileSizeAuthor
#74 364470-74-submitted-by.patch9.44 KBJohnAlbin
PASSED: [[SimpleTest]]: [MySQL] 27,400 pass(es).
[ View ]
#69 364470-69-submitted-by.patch9.51 KBJohnAlbin
PASSED: [[SimpleTest]]: [MySQL] 27,384 pass(es).
[ View ]
#65 364470-65-submitted-by.patch9.54 KBJohnAlbin
FAILED: [[SimpleTest]]: [MySQL] 27,378 pass(es), 0 fail(s), and 194 exception(es).
[ View ]
#52 364470-node-submittedby-regression-D7.patch6.79 KBDave Reid
FAILED: [[SimpleTest]]: [MySQL] 26,784 pass(es), 3 fail(s), and 0 exception(es).
[ View ]
#49 364470-node-submittedby-regression-D7.patch6.72 KBDave Reid
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in comment.tpl.php.
[ View ]
#48 364470-node-submittedby-regression-D7.patch8.98 KBDave Reid
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in comment.tpl.php.
[ View ]
#44 364470-node-submittedby-regression-D7.patch769 bytesDave Reid
PASSED: [[SimpleTest]]: [MySQL] 26,338 pass(es).
[ View ]
#39 2010-10-19_13.14.00.png120.84 KBDanny Englander
#21 submitted-no-more-364470-21.patch11.43 KBJohnAlbin
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch submitted-no-more-364470-21.patch.
[ View ]
#19 submitted-no-more-364470-19.patch10.39 KBJohnAlbin
Failed: 12407 passes, 1 fail, 0 exceptions
[ View ]
#9 364470_submitted-9.patch11.63 KBstBorchert
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 364470_submitted-9.patch.
[ View ]
#4 364470_submitted-4.patch9.75 KBstBorchert
Failed: Failed to apply patch.
[ View ]

Comments

JohnAlbin’s picture

Issue tags:+theme, +tpl-refresh

I remember this being one of the first things I wanted to do when I learned Drupal theming. And it was too complex to do.

Learning theme() functions is an intermediate-level theming skill. But changing how my name and date appear on my posts is an über-newbie theming desire.

Looks like we should probably use best practices with the t() function when adding this to node.tpl:
<?php print t('Submitted by !author on @date', array('!author' => $author, '@date' => $submitted_date); ?>

Its more complex, which is bad for newbies. :-( But the alternative, unfortunately, would be impossible to translate:
<?php print t('Submitted by'); ?> <? print $author; ?> <?php print t('on'); ?> <?php print $submitted_date; ?>

geerlingguy’s picture

I am definitely +1 on this. I just changed things on stlouisreview.com's articles, and it took me a great deal longer than I would've liked. I ended up trashing the idea of modifying the themeable function, and simply rewriting the PHP in node.tpl.php to suit my desire.

stBorchert’s picture

As noted in #382870: Update and Polish Node Template Output I would suggest using an additional template for the output of the submitter information.

Quick proposal (unfortunately I can't create patches from here):

<?php
// $Id: submitted.tpl.php $

/**
 * @file
 * Default theme implementation to present the submitted information for a
 * node object.
 *
 * Available variables:
 * - $username: Name of the user who submitted the node.
 *
 * - $datetime: The timestamp on which the node has been created.
 *
 * @see template_preprocess_submitted()
 */

?>

<div class="submitted">
  <?php print t('Submitted by !author on @date', array('!author' => $username, '@date' => $datetime); ?>
</div>

-------------------------------------------------------------------------

<?php
function node_theme() {
  return array(
   
// ...,
   
'submitted' => array(
     
'arguments' => array('node' => NULL),
     
'template' => 'submitted',
    ),
   
// ...
 
);
}

function

template_preprocess_submitted(&$variables) {
 
$node = $variables['node'];
 
$variables['username'] = theme('username', $node);
 
$variables['datetime'] = forma_date($node->created);
}
?>

Stefan

stBorchert’s picture

Status:Active» Needs review
StatusFileSize
new9.75 KB
Failed: Failed to apply patch.
[ View ]

This patch introduces two new templates:
* comment_submitted.tpl.php
* node_submitted.tpl.php

geerlingguy’s picture

I'm liking it. A lot. Makes it 20x easier to change that text! I would like someone else to RTBC, but I approve wholeheartedly.

catch’s picture

Does the phpdoc for theme() need changing (mentions $submitted a few times)?

stBorchert’s picture

Yes, think so. $submitted isn't a good example for the use of preprocess-functions anymore.
The question is: which one do we want to take instead?
template_preprocess_node contains

  • build_mode
  • teaser
  • node
  • date
  • name
  • node_url
  • title
  • page
  • submitted
  • picture
  • classes-array
  • promote
  • sticky
  • status
  • preview
  • template-files
  • and the flattened node object

"submitted" was the best candidate until now. What about using "classes-array" in phpdoc?

Status:Needs review» Needs work

The last submitted patch failed testing.

stBorchert’s picture

Status:Needs work» Needs review
StatusFileSize
new11.63 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 364470_submitted-9.patch.
[ View ]

Re-rolled because #382870: Update and Polish Node Template Output changed node.tpl.php.
Updated phpdoc for theme() (used $classes-array instead of $submitted).

geerlingguy’s picture

lol - sorry about that business with the node.tpl.php...

Tested, patch applied, seems to function. I'd rather not RTBC, though, as I'm not 100% on the logic—it seems fine to me, but I don't know enough about Drupal to approve committing it to core :-)

tic2000’s picture

Status:Needs review» Needs work

I think that creating a new template file just for the submitted part is both too much and not useful. For one if you do it this way you can't, as in OP example, have the date on top and author on bottom of the node or the other way around.

I think JohnAlbin's suggestion is a good one. A proper use of t() inside node.tpl.php. Yes, it may be complex, but I don't think moving it in another file makes themers life easier.

stBorchert’s picture

Status:Needs work» Needs review

For one if you do it this way you can't, as in OP example, have the date on top and author on bottom of the node or the other way around.
Sure, you can. $node holds exactly this information. And you can put it wherever you like.

A proper use of t() inside node.tpl.php
The intention of this patch was to remove complexity not to add some.

tic2000’s picture

And how is this less complex?
Instead of having the function inside node.tpl.php you have to find the file where that $submitted comes from only to find the exact same function you say it's too complex.
What stops you now to use the info you have in $node? The fact that you are new to Drupal and don't know what's inside $node and if you manage to find out you don't know how to convert $node->created to a nice readable date because you are "just" a themer.

IMO this patch doesn't make life easier for new themers to achieve what JohnAlbin mentions in #1.

geerlingguy’s picture

@tic2000 - imo, xxx.tpl.php files are much more easy to wrap your mind around for non-programmers (especially those who don't have as much PHP knowledge) than themeable functions. Just my perspective, being a designer/not a programmer.

Edit: Another note... node.tpl.php already has a boatload of logic inside, imo. The less the better...

tic2000’s picture

@geerlinguy
You don't get my point. This issue was opened because that $submitted variable is not themer friendly. Now, instead of using t() inside node.tpl.php we use a theme file which has the function inside. So inside node.tpl.php you still have the same $submitted variable. Using another file you don't make $author or $date available inside node.tpl.php so the themer has to learn where he can find that info and how he can transform it in something he can use. This is exactly the situation now, no improvement.
Again a themer won't be able to move $author or $date around. The only minor improvement is that he can now find easier where $submitted is generated.

Themers are not stupid. If they see the t function with !author and $author in it they will figure that out. Figuring out how he can use $author from another template file inside node.tpl.php will require a lot more knowledge.

I, as a themer I would prefer to see the t() in node.tpl.php. It would give me the freedom to move the author or date around. It won't force me to move the whole submitted text around and author and date only inside that text.
If it's not, I would at least like to have $author, $date and even $time_ago available for use in node.tpl.php.

geerlingguy’s picture

@tic2000 - the only thing is, I've never seen t() used inside node.tpl.php, and I think we're already starting to see a lot more logic inside of these template files than most non-Drupal themers/designers are used to...

But I get your point; the logic is simply moved to another tpl.php file... it's an interesting dilemma, to be sure. I'd rather vote to keep it separate, just for the sake of keeping node.tpl.php as free of logic as possible, because it's probably one of the template files touched by most new themers, along with page.tpl.php.

tic2000’s picture

In that case you don't solve the problem pointed in OP and #1.
It can be kept separate, but also add $author and $date and maybe even $time_ago as variables available for node.tpl.php too.

stBorchert’s picture

@tic2000: the variables already exist in node.tpl.php (and wouldn't be removed by this patch).

* Available variables:
* ...
* - $date: Formatted creation date (use $created to reformat with
*   format_date()).
* - $name: Themed username of node author output from theme_username().
* ...
JohnAlbin’s picture

StatusFileSize
new10.39 KB
Failed: 12407 passes, 1 fail, 0 exceptions
[ View ]

Yeah, moving the locked-together variables from a theme function to a template doesn't help much as we usually want to separate them.

the only thing is, I've never seen t() used inside node.tpl.php

We have 6 of them in page.tpl.php. :-)

And t() has to be used if we want any words hard-coded in a tpl because, of course, they have to be translatable from English to the end user's language.

Here's a patch that gets rid of node_submitted and comment_submitted theme functions and replaces them with calls to t().

Status:Needs review» Needs work

The last submitted patch failed testing.

JohnAlbin’s picture

Status:Needs work» Needs review
StatusFileSize
new11.43 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch submitted-no-more-364470-21.patch.
[ View ]

Updated patch fixes broken tests.

stBorchert’s picture

While I really like my solution yours is more simple and looks really good :-).
So RTBC from me.

tic2000’s picture

Status:Needs review» Reviewed & tested by the community

Since I suggested exactly this solution and the bot likes it too RTBC.

webchick’s picture

Status:Reviewed & tested by the community» Needs work
Issue tags:+Needs Documentation

I thought about this patch for awhile...

Displaying the post date without the author is one of the very first things I wanted to do on webchick.net, since -- obviously -- all of the posts on there are by "webchick" so it's redundant to keep repeating it. I was appalled that fixing this meant I had to either hack Garland or make a custom theme (I have since been given a custom theme by quicksketch, so this is more of a moot point now, but still annoying).

So I made #216961: Make author/submitted by separate toggles in the hopes of addressing it. Unfortunately that issue ballooned in complexity as we started really looking into what it would take to fix this; for example the date formats and what not. Additionally, if you start down this road, what DON'T you add a configuration setting for? Why not the div surrounding the submitted-by information too, while we're at it? :P

With this approach, as opposed to the submitted.tpl.php approach, I could at least use the languages override in settings.php to change my formats without hacking the theme. I agree t() in tpl.php files is a little funny, but in this case I think it really does give us the most bang for our buck, and makes it trivial for someone who is cool with theming to jump in here and monkey with stuff.

Therefore, committed to HEAD, and marked the other issue as a dupe. This needs updating in the theme upgrade guides. Well done, folks!

geerlingguy’s picture

Hooray! Thank you, webchick!

Danny Englander’s picture

Status:Needs work» Needs review

#21: submitted-no-more-364470-21.patch queued for re-testing.

aspilicious’s picture

highrockmedia this is already committed to head...

It needs documentation + upgrade path I guess...

Status:Needs review» Needs work

The last submitted patch, submitted-no-more-364470-21.patch, failed testing.

mariusz.slonina’s picture

Hm, on the other hand, I tried to create a minimal theme _without_ touching default template files, as described here: #812796: Theme API feels to be incomplete. I added there a patch also for... restoring $submitted (as I didn't found this topic before), because it allows me to change submitted message hardcoded right now in node.tpl.php or comment.tpl.php without overriding these files. To have completely rewritten submitted message without using custom node.tpl.php I need to translate the string, right? (which I don't want to do, and I feel it is not the way...). With some kind of "submitted" variable I am able to produce theme, that will include only 4 files: info, reset.css, style.css and template.php with all flexiblility of the theme api. Having all other variables not hardcoded in template files -- and only submitted message hardcoded -- seems a little bit strange for me, just because I learned that Drupal is very flexible. As a "local" themer, webdeveloper and software engineer I miss $submitted variable, it was for me much more cleaner, and "compact" to adjust it in the template.php.

Adam S’s picture

Status:Needs work» Needs review

#9: 364470_submitted-9.patch queued for re-testing.

Jonah Ellison’s picture

I've been working with the Zen 2.0 theme and discovered they already backported this patch to Drupal 6, which was a rather frustrating experience. I agree with mariusz -- I miss $submitted. I was hoping to make my Zen subtheme small and compact, but I had to copy over node.tpl.php for a simple text change.

This patch makes node rendering less modular, since the template file "owns" the submitted text. If someone had a module that required changing the node submit text, they can no longer do this through preprocess hooks. Even the theme's own template.php file cannot change the text.

I don't agree with this patch for the sake of making it easier for newbies while sacrificing the modular nature that makes Drupal so great.

Dave Reid’s picture

With this patch we removed flexibility in being able to edit the submitted by information on specific node types or nodes, rather than globally, which is what a settings.php language override would do... We now have to hack core to be able to truly change this.

NancyDru’s picture

Argghhh!!! This whole thing is a bad idea!!!

Submitted By gives users the total flexibility of Tokens and changing the string by content type. And the module was even originally created by a core maintainer.

This is a huge step backwards. Please consider backing this whole thing out.

Dave Reid’s picture

Priority:Normal» Major

Upgrading this to major. This needs some responses from those working on the initial patch as to how we can solve this.

Dave Reid’s picture

Title:Easier theming of "Submitted by author, on date"» [Regression] Easier theming of "Submitted by author, on date"
Category:task» bug
NancyDru’s picture

Do a search on theme_node_submitted and you will see many posts where users have developed sites based on that function. All of their sites will go down the drain. I have no idea how many themes will be broken.

tic2000’s picture

Assigned:ineation» Unassigned
Category:bug» task
Priority:Major» Normal
Status:Needs review» Needs work

@mariusz
As you noticed in that issue you have to actually add or change a lot of stuff to get a simple theme. And that supposing the markup in the default files is everything you want, which rarely is, which means yours is an edge case.

@Jonah
So you install a theme (Zen) and create a subtheme, but yo have a big issue with the fact that you need to add node.tpl.php to your theme. Well, that's not compact anyway.

@Dave
No we didn't. How could you edit $submitted before? Preprocess hook in template php or a node.tpl.php file for each node type. You can do both now. With the preprocess hook you will need to change that t() back to $submitted and create the $submitted variable in the preprocess hook for each node type like in D6.

@Nancy
You talk about a module that for multi language sites needs the settings.php technique to translate the output.
I searched like you suggested and I did not see those issues with sites "based on that function". And even if they based their sites on that function the change they will require, like I already explained to Dave, should be trivial, so it will not throw their sites down the drain.

The issue was to make that variable easier for themers. That's one think a lot of new Drupal users try to do and it was not easy. Even for a developer new to Drupal it was not easy. It required more time than it does now.

This is by design. It's not a bug, and it's not a regression.

tic2000’s picture

Title:[Regression] Easier theming of "Submitted by author, on date"» Easier theming of "Submitted by author, on date"
Danny Englander’s picture

StatusFileSize
new120.84 KB

I am not sure if this is relevant (or offers enough flexibility) but I typically do something like this in my node-custom.tpl.php. That seems fairly "easy" to me as a front end developer / themer. :)

<div class="meta post-info">
<?php if ($submitted): ?>
<span class="submitted">Posted by <?php print theme('username', $node) ?></span>
<?php endif; ?>

<!--start theming-->
<div class="dateblock">
<span class="month"><?php print $date_month ?></span>
<span class="day"><?php print $date_day ?></span>
<span class="year"><?php print $date_year ?></span>
</div><!--//end dateblock-->
<!--end theming-->
</div><!--//end meta post-info-->

...and then of course however you want to do CSS for the above -- I have attached a screen capture how it looks on my website.

NancyDru’s picture

You do understand that there will be no $submitted with this change? In 6.x you don't have to do that at all if you recommend the Submitted By module to your users, which gives people the opportunity to change the submitted by line for each content type in any way they like. This partially committed change is a big step backwards in theming IMHO.

@tic2000: if Submitted By is not working the way you think it should, then please submit a feature request (preferably with a patch). This is not the place to discuss that issue.

Jonah Ellison’s picture

tic2000, the argument is that we want the submitted by text to remain modular and flexible.

For example, if a site is using Garland and the user wants to change the submit formatting, this can't be done without hacking core due to this patch.

Part of successful Drupal theming is learning template variables, theme override functions, and preprocess hooks. I'd rather that newbies learn how to properly theme Drupal elements instead of giving an easy way out like this.

NancyDru’s picture

"An easy way out" that will come back to bite them later.

In all the sites that I have developed, I can count on one hand the number of times I've had to resort to a node-xxx.tpl.php, which I would believe I would be doing a lot of with this "improvement."

With all my modules, I often get posts from people who claim they can't code, but are happy (even desire) to theme various elements. I absolutely agree with Jonah on his statement.

webchick’s picture

It sounds like those advocating for a roll-back have presented some pretty compelling evidence that we lost a lot of flexibility with this change. I agree that copy/pasting a bunch of node-XXX.tpl.php files around for the purposes of changing one line of code is sub-optimal.

JohnAlbin, geerlingguy, do you have a response?

Dave Reid’s picture

Status:Needs work» Needs review
StatusFileSize
new769 bytes
PASSED: [[SimpleTest]]: [MySQL] 26,338 pass(es).
[ View ]

My proposal is to make just a simple change to the default node.tpl.php to allow $display_submitted to be a string that is inserted directly, but also support the true/false logic with the default string.

NancyDru’s picture

@Dave: how is that different from the D6 $submitted variable? Most themes use that today, and those that don't were slowly getting the religion.

@Angie: not just "changing one line of code," but one line that is easily themed and/or altered to the user's desires. Not to mention in use on many sites (do a search on "submitted by") that would now have to change one more thing in order to get to D7.

I certainly don't mind presenting more variables to the templates but you open a can of worms: "You added xxxx. so why not yyyy?" and "Why not just pass every token that's available?" (You have know that will come probably sooner rather than later.)

webchick’s picture

Status:Needs review» Needs work

Well. If we're going that route...

a) It should revert back to the old name $submitted.
b) It needs to be documented in node.tpl.php.
c) We should set it up somewhere in theme.inc/node.module.

JohnAlbin’s picture

So, I see this issue as a pendulum thing. Before the $submitted_by variable was non-obvious to change by themers. This fact drove the development of modules like NancyDru's, since it was relatively easy for modules to change the variable.

Now in d7, we've gone to the other extreme (unintentionally), themers can easily see how to change this text, but modules are completely shut out. That was not my intention with the original patch, btw.

I'm okay with davereid's compromise. It is slightly icky in that it checks for is_string() in the template, but it does provide for both themer and module developer modification of the text.

Dave Reid’s picture

StatusFileSize
new8.98 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in comment.tpl.php.
[ View ]

Feels like we should just make the submitted by information just work like everything else in the templates, and just add it using preprocess. No crazy theme functions just for the submitted by information, but anyone would have to learn how to use preprocess properly to override any of the other variables, so I think this makes a lot of sense.

Dave Reid’s picture

Status:Needs work» Needs review
StatusFileSize
new6.72 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in comment.tpl.php.
[ View ]

Ack, extra hunks not removed from that patch.

Dave Reid’s picture

The only downside to this is Bartik doesn't use this at all and splits its information up into a separate paragraphs for username and date, but that's a downside regardless of this patch.

Status:Needs review» Needs work

The last submitted patch, 364470-node-submittedby-regression-D7.patch, failed testing.

Dave Reid’s picture

Status:Needs work» Needs review
StatusFileSize
new6.79 KB
FAILED: [[SimpleTest]]: [MySQL] 26,784 pass(es), 3 fail(s), and 0 exception(es).
[ View ]

Status:Needs review» Needs work

The last submitted patch, 364470-node-submittedby-regression-D7.patch, failed testing.

Dave Reid’s picture

@all: Does the solution in #52 seems reasonable for me to proceed rolling it?

Dave Reid’s picture

Assigned:Unassigned» Dave Reid
NancyDru’s picture

I haven't tested it, but the code looks like it should take care of my objections and keep the Submitted By module working.

Dave Reid’s picture

Priority:Normal» Major

Bumping to major.

NancyDru’s picture

Personally, I would mark it as "release blocker."

jensimmons’s picture

subscribe

Dave Reid’s picture

Issue tags:+string freeze, +API change

This indeed is something that *has* to be fixed before 7.0.

geerlingguy’s picture

Ah crud. /me slaps himself in the face. After 1.5 years, I disagree with pretty much everything I said in the first replies. I'm all for Dave's use of preprocess functions. Don't have time right now to test this patch, though.

Dave Reid’s picture

Could also use some help figuring out why the rdf_test module suddenly fails with this.

Dave Reid’s picture

OH %@^@$#... rdf_process() and rdf_preprocess_node() both have to run after template_preprocess_node() somehow. This sucks.

JohnAlbin’s picture

I see how to fix the RDF issue. Rolling a patch now. Temp work at https://github.com/JohnAlbin/drupal/tree/364470-submitted-by

Also, Dave's patch obliterates both Garland's and Bartik's preferred language around the name and date variables.

JohnAlbin’s picture

Priority:Major» Critical
Status:Needs work» Needs review
StatusFileSize
new9.54 KB
FAILED: [[SimpleTest]]: [MySQL] 27,378 pass(es), 0 fail(s), and 194 exception(es).
[ View ]

Updates since patch in #52:

  • Add RDF attributes to node's and comment's $submitted variable.
  • Change node submitted variable to use empty string instead of FALSE.
  • Remove conditional printing of comment submitted since its always present.
  • Fix submitted strings in Bartik and Garland.
  • Make comment module's submitted variable translation string match node module's. Comment module's submitted by string was identical to node module's, except that it had a period at the end. Pointlessly different, IMO.

Since this tweaks a translation string, I'm bumping this to critical so it goes in before RC1 (string freeze).

Status:Needs review» Needs work

The last submitted patch, 364470-65-submitted-by.patch, failed testing.

tim.plunkett’s picture

sub

JohnAlbin’s picture

What the… I fixed the RDF issue, but borked the upgrade path??? /me scratches head and investigates.

JohnAlbin’s picture

Status:Needs work» Needs review
StatusFileSize
new9.51 KB
PASSED: [[SimpleTest]]: [MySQL] 27,384 pass(es).
[ View ]

ha! I used $variables instead of $vars in Garland's template.php. Stupid Garland. Someone should fix that inconsistency. Oh, wait. #975168: Add JohnAlbin to MAINTAINERS.txt Crap.

Anyways, here's an updated patch.

Status:Needs review» Needs work

The last submitted patch, 364470-69-submitted-by.patch, failed testing.

EvanDonovan’s picture

I am so glad you are adding $submitted back in. Preprocess seems like the most logical place to generate it, and would allow you to modify it on a node-type basis.

JohnAlbin’s picture

Status:Needs work» Needs review

#69: 364470-69-submitted-by.patch queued for re-testing.

tim.plunkett’s picture

Status:Needs review» Needs work

Removing $display_submitted breaks the ability to easily override $submitted in a template_preprocess_node(), because if you override it will print regardless of the node setting. Otherwise you'd have to foreach over 'node_submitted_' . $node->type every time, which would be bad DX (TX?).

JohnAlbin’s picture

Status:Needs work» Needs review
StatusFileSize
new9.44 KB
PASSED: [[SimpleTest]]: [MySQL] 27,400 pass(es).
[ View ]

I agree with Tim. The patch in #69 demonstrates that it is very easy for a themer to forget to check that variable before creating a new $submitted value. Unintentionally in that patch, I made both Bartik and Garland always output the $submitted variable even if the node submitted by display setting was off.

Here's a new patch that adds $display_submitted back in.

JohnAlbin’s picture

Priority:Critical» Major

Oops. misread webchick's comments about string freeze changes. should be tagged "string freeze" but left at major priority.

JohnAlbin’s picture

As a themer, this isn't a critical issue since I can easily modify what I need. I would prefer the patch to what's in D7 now, but if it doesn't get in I won't be greatly annoyed. (unlike for some issues)

For those who consider this essential to d7, review! Time's a wastin'. 1 week until RC1. tick. tick. tick.

Dave Reid’s picture

+++ themes/garland/template.phpundefined
@@ -114,6 +114,20 @@ function garland_preprocess_page(&$vars) {
/**
+ * Override or insert variables into the node template.
+ */
+function garland_preprocess_node(&$vars) {
+  $vars['submitted'] = $vars['date'] . ' — ' . $vars['name'];
+}
+
+/**
+ * Override or insert variables into the comment template.
+ */
+function garland_preprocess_comment(&$vars) {
+  $vars['submitted'] = $vars['created'] . ' — ' . $vars['author'];

Don't these preprocess functions completely negate any changes made by modules to $vars['submitted']?

+++ themes/bartik/template.phpundefined
@@ -100,6 +100,13 @@ function bartik_process_maintenance_page(&$variables) {
/**
+ * Override or insert variables into the node template.
+ */
+function bartik_preprocess_node(&$variables) {
+  $variables['submitted'] = t('published by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));

Same

Powered by Dreditor.

JohnAlbin’s picture

Don't these preprocess functions completely negate any changes made by modules to $vars['submitted']?

Not if the module is smart and does its work in MODULE_process_node() and MODULE_process_comment(). :-D

mariusz.slonina’s picture

Thank You for work on this issue. I applied the patch and rebuild my custom theme with $submitted variable -- it seems to work nice and it is much much closer to css-only theme with many things overridden with template functions in template.php :) As a simple test, I also added a template.php to Stark, and used preprocess functions for node and comments to achieve custom $submitted. It's a flexible solution, as in my opinion should be :)

EvanDonovan’s picture

Just from looking at the code this looks like a clean solution. I'd like to mark RTBC, but I don't have the time right now to actually test by modifying a theme.

tim.plunkett’s picture

Status:Needs review» Reviewed & tested by the community

This is ready. And it makes so much more sense.

webchick’s picture

Status:Reviewed & tested by the community» Fixed

I really hate to make a change like this this late, but the evidence for rolling back is pretty compelling, even coming from the original authors.

So, committed to HEAD.

Please formulate exactly what changed here so that Randy can announce to the dev list.

NancyDru’s picture

Yay, thanks, Angie.

rfay’s picture

Yes, if this is an API change that could affect existing code, please summarize here so it can be announced.

Thanks!

JohnAlbin’s picture

@rfay:

Previously in D7, the "Submitted by…" text for node and comment tpls was created with a t() function that resided directly in the node.tpl.php and comment.tpl.php. With this API change, the node's $name and $date variables are joined together inside template_preprocess_node() and printed as a $submitted variable in the node.tpl.php. The comment's $author and $created variables are now joined together inside template_preprocess_comment() and printed as a $submitted variable in the comment.tpl.php.

NancyDru’s picture

And, this means that "Themes should become more consistent is using the $submitted variable rather than creating their own. This, in turn, allows site maintainers greater flexibility in controlling the submitted-by line."

jhodgdon’s picture

Status:Fixed» Needs work

Needs to be added to the 6/7 theme and module update guides too, right?

Dave Reid’s picture

Yes it should, considering the first time this was changed, it didn't make it in the upgrade guide either...

jhodgdon’s picture

Changing the tag. As of now, we are using the tag "Needs Update Documentation" to designate issues that need documentation in the 6/7 update guides (module or theme).

polishyourimage’s picture

subscribing

Frank Pfabigan’s picture

subscribing, +1

a1tsal’s picture

+1...

davidsanger’s picture

So if the change has been made how do I change the "submitted by" text in Drupal 7 ?

jhodgdon’s picture

Comment #85 has an issue summary. It still needs to be documented in the theme and module upgrade guides.

dantje’s picture

@davidsanger:

What worked for me:

Currently in Bartik's node.tpl.php the following code appears:

<?php print $submitted; ?>

In order to display the author name only, I replaced it with:

<?php print $name; ?>

And you can add the "posted by" if you like:

<?php print 'Posted by ' . $name; ?>

And for the date only add:

<?php print $date; ?>

(I couldn't find where to change the "posted by" not in an overriding nature like the method above, I'm quite new to the coding aspect... Maybe there's a cleaner way).

jhodgdon’s picture

Status:Needs work» Fixed

Just as a note - the issue summary in #85 is misleading -- that tells what happened late in this issue, not what changed between d6 and d7.

What really has apparently changed between D6 and D7 in relation to the $submitted variable is that in D6, it was created in template_preprocess_node by a call to theme('node_submitted'), and in d7, it is created in template_preprocess_node by

$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));

So I don't really think this is much of a 6/7 API change. The separate $name and $date variables existed in d6 as well. The only API change between 6 and 7 is that theme_node_submitted no longer exists.

I've documented this in:
http://drupal.org/update/themes/6/7#submitted_by
I don't think it deserves a mention in the module update guide, so I think this is done.

Status:Fixed» Closed (fixed)
Issue tags:-theme, -string freeze, -tpl-refresh, -API change, -Needs Update Documentation

Automatically closed -- issue fixed for 2 weeks with no activity.

dangswiss’s picture

Issue summary:View changes

Thanks, @jhodgdon your comment gave me exactly what I needed!
I posted my solution at https://groups.drupal.org/node/132554#comment-1048128