Problem/Motivation

The motivation here is simply best practices for Drupal. The problem is the implementation of hook_field_formatter_settings_summary(), which has the following:
$summary = t('Trim length') . ': ' . $settings['trim_length'];
As the title says, this shouldn't be done like this.

Proposed resolution

I suggest we use an @placeholder like everywhere else in this module.

$summary = t('Trim length: @trim_length', array(
  '@trim_length' => $settings['trim_length'],
));

I'll add a comment with a patch.

Remaining tasks

The entire D8 change can't be backported due to it breaking translations.

The change to D8 added variable sanitization where there was none previously. A patch to backport the variable sanitization exists in #9.

User interface changes

None.

API changes

None.

Comments

carwin’s picture

Notes

  • First patch is for Drupal 8
  • Second patch is for Drupal 7

The only reason the same patch cannot be applied is that the function starts one line higher in d8 than in d7.

Status: Needs review » Needs work

The last submitted patch, text-do-not-concat-variables-t-function-1790612-1.patch, failed testing.

carwin’s picture

Status: Needs work » Needs review
StatusFileSize
new619 bytes

Oopsie daisy, forgot a parentheses in the d8 version.

das-peter’s picture

As carwin mentioned I'd say this is RTBC. But another review would be nice :)

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Nice catch.
I don't think this can be backported without breaking existing translations.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thanks.

eric_a’s picture

Version: 8.x-dev » 7.x-dev
Category: task » bug
Status: Fixed » Needs review
Issue tags: +Needs backport to D7
StatusFileSize
new602 bytes

Sanitizing of the trim_length variable sneeked in with the t() concat fix. Here's a patch that does just the sanitizing for D7.

tstoeckler’s picture

format_string() seems a little verbose for that. Can't we do a check_plain() directly?!

eric_a’s picture

StatusFileSize
new566 bytes

Yeah.
BTW, the patch in #7 is missing quotes around the array key...

tstoeckler’s picture

...which means this isn't tested at all :-/
That shouldn't be part of this issue, though.

mgifford’s picture

Issue summary: View changes

@Eric_A the latest patch still applies.

This is a 1 line patch that's already in D8. Should be an easy fix.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

#9 looks ok to me. It only adds sanitization where there is none.

dcam’s picture

Issue summary: View changes

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: text-check_plain-1790612-9.patch, failed testing.

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Reviewed & tested by the community
tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work

Sorry for only noticing this now but I think the D7 version should follow what the D8 version does, i.e. see the patch in #3.

mgifford’s picture

Status: Needs work » Needs review
StatusFileSize
new599 bytes

Good point @tstoeckler - The D8 way should be better for translation. However, it will be a change so that string will need to be adjusted in the existing translations.

tstoeckler’s picture

Issue tags: +Needs manual testing

Ahh, right. That's true. Hmm... maybe that's why the patch in #9 was proposed in that way? Not sure.

Anyway, it seems due to #9/#10 this needs manual testing? Otherwise it's RTBC.

Sorry for holding this up :-/

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Yeah, in #7 it was noted that the 8.x fix happened to add variable sanitization where there previously was none. So that's the only 8.x change that @Eric_A sought to backport.

Moving #9 back to RTBC.

tstoeckler’s picture

OK, sorry for the noise.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: text-check_plain-1790612-18.patch, failed testing.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

#9 still RTBC.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed #9 to 7.x - thanks!

I think the full patch could be backported if necessary (i.e. if it's actually causing problems with real translations), especially since it's an admin-facing string (https://www.drupal.org/node/1527558) - would just want to do it early in the release cycle.

But will leave it to someone to reopen for that only if it's causing an actual translation problem in its current state.

Status: Fixed » Closed (fixed)

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