Hi,

The line below breaks the site when using the site in multi - language mode.

<?php
define('CSHS_DEFAULT_NONE_LABEL', t('- Please select -'));
?>

cshs/cshs.module

Error: "Fatal error: Call to a member function getRequestUri() on null"

Steps to reproduce it:

- Install Drupal in another language than English
- Enable cshs module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpastas created an issue. See original summary.

mpastas’s picture

mpastas’s picture

Patch added.

dagmar’s picture

Status: Active » Needs work
  1. +++ b/cshs.module
    @@ -5,7 +5,7 @@
    +define('CSHS_DEFAULT_NONE_LABEL', '- Please select -');
    

    If this default is not used, you could delete it.

  2. +++ b/src/Element/CshsElement.php
    @@ -27,7 +27,7 @@ class CshsElement extends Select {
    +    $info['#none_label'] = t(CSHS_DEFAULT_NONE_LABEL);
    

    check if you can use $this->t() at this stage

mpastas’s picture

You are right Mariano. Patch updated.

mpastas’s picture

Status: Needs work » Needs review
dagmar’s picture

Status: Needs review » Reviewed & tested by the community

Nice

BR0kEN’s picture

Status: Reviewed & tested by the community » Needs work

Constant also used in CshsOptionsFromHelper.

dagmar’s picture

Status: Needs work » Needs review
FileSize
1.41 KB

Thanks. Here is the patch.

gngn’s picture

Just a tiny thing: #9 changes CshsOptionsFromHelper from

-        'name' => CSHS_DEFAULT_NONE_LABEL,

to

+        'name' => t('CSHS_DEFAULT_NONE_LABEL'),

We should drop the single-quotes to actually translate '- Please select -'.

+        'name' => t(CSHS_DEFAULT_NONE_LABEL),

Although I didn't see 'CSHS_DEFAULT_NONE_LABEL' on my screen - does somecode overwrites the '- Please select -' from CshsOptionsFromHelper::getOptions()?

Also I'm not sure about using t() with a constant...

dagmar’s picture

Status: Needs review » Reviewed & tested by the community

Right. Thanks @gngn.

Also I'm not sure about using t() with a constant...

This is ok, the recommendation is not use variables insde t().

mpastas’s picture

Patch updated based on dev version.

BR0kEN’s picture

Since we are passing non string literals as argument for t(), but completely sure that value - is a string, then we have to prevent codesniffer warnings using special tags. Also, $this->t() have to be used wherever possible.

  • BR0kEN committed cf21a35 on 8.x-1.x
    Issue #2774919 by mpastas, BR0kEN, dagmar, gngn: CSHS_DEFAULT_NONE_LABEL...
BR0kEN’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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