I've just had this:
Notice: Undefined property: Drupal\Core\Language\Language::$language in Drupal\typogrify\Plugin\Filter\TypogrifyFilter->process() (line 317 of /var/www/yaffs/web/modules/contrib/typogrify/src/Plugin/Filter/TypogrifyFilter.php). array(36)

My site is a development site which I installed with Drupal console. It's in English, but I can't ever remember setting a default language, and line 317 should work...

 if ($langcode == 'und') {
      $language = \Drupal::languageManager()->getCurrentLanguage();

      // @fixme, check language business for d8
      $ctx['langcode'] = $language->language; // This is line 317.
    }
    else {
      $ctx['langcode'] = $langcode;
    }

I have no default locale set.
I do not have the Language module enabled. This is probably the root cause.

CommentFileSizeAuthor
#4 2863904-typogrify-langcode-4.patch1013 bytesbenjifisher

Comments

Jeff Veit created an issue. See original summary.

jeff veit’s picture

Running D8.2.7

pcranston’s picture

I was getting this same notice within Views. I also don't have Locale installed, and it's an English language site. For me, I fixed the issue by changing that line 317 to:

$ctx['langcode'] = 'en';

and it works fine now. More of a hack than an official fix though.

benjifisher’s picture

Title: Bug - no default language » Typogrify does not handle langcode properly
Status: Active » Needs review
StatusFileSize
new1013 bytes

I was not able to reproduce the problem: for me, $langcode is already set to "en", not "und". I even tried downgrading to Drupal 8.2.7. But I tested that code path, and the attached patch should fix the problem. It would be good to get testing from someone who saw the problem.

brightbold’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #4 solved the problem for me. Thanks Benji!

benjifisher’s picture

@BrightBold: Thanks for testing!

brightbold’s picture

Hmm, I'm now getting two new errors which may be unrelated, but I thought I'd mention them here in case there's a possibility they were caused by this patch. (If not, I'll open a new issue.)

  • Warning: Illegal string offset ',,' in Drupal\typogrify\Plugin\Filter\TypogrifyFilter->tips() (line 457 of modules/contrib/typogrify/src/Plugin/Filter/TypogrifyFilter.php).
  • Notice: Undefined variable: ascii_to_unicode in Drupal\typogrify\Plugin\Filter\TypogrifyFilter->tips() (line 460 of modules/contrib/typogrify/src/Plugin/Filter/TypogrifyFilter.php).
benjifisher’s picture

@BrightBold:

That looks like a separate error. If you un-apply this patch, do you still get that error? Or do you not get that far?

It looks pretty harmless, since the tips() method just generates the help text about the filter.

What version are you using? (Likely choices are 8.x-1.0-alpha1 and 8.x-1.x.) Are you using any other patches?

Some lines from approximately the right place are

      // Build a list of quotation marks to convert.
      foreach (UnicodeConversion::map('quotes') as $ascii => $unicode) {
        if ($settings['quotes'][$ascii]) {
          $ascii_to_unicode .= $this->t('Converts @ascii to @unicode', array(
            '@ascii' => $ascii,
            '@unicode' => $unicode,
          ));
          $output .= "<li>$ascii_to_unicode</li>\n";
        }

The $ascii_to_unicode variable does not appear anywhere else, so the $ascii_to_unicode .= ... line is probably responsible for the Notice. The warning comes from $settings['quotes'][$ascii] when $ascii is the string ',,'.

If you only started seeing these messages now, I think it is either because you are using a different version of PHP or you have changed your error-reporting level.

brightbold’s picture

As I am unhelpfully reporting this information to you verbally right now, I will also document it in the issue queue:

  • Yeah you caught me. I didn't uninstall the patch and attempt to reproduce. Sorry.
  • It was indeed on the format tips page, so if it's only thrown there, I guess that's not a huge problem if your clients don't have permissions to see errors. But it sure makes the tips page look ugly.
  • I'm using the dev version and no other patches that I can recall.
  • I suspect I am only seeing this error now because I have never, in 10+ years of using Drupal, clicked the "About text formats" link, until yesterday.
benjifisher’s picture

I just added #3024642: PHP warning when viewing help text and #3024641: Undefined variable notice when viewing filter help text for the two problems you reported. (I am pretty sure it is two separate issues.) One of them is a Novice issue, so someone is likely to work on it pretty soon.

brightbold’s picture

Thanks Benji!

wim leers’s picture

Tested, and confirming RTBC! 🥳

cobenash’s picture

Tested.

Confirmed.

  • benjifisher authored 9f01a48 on 8.x-1.x
    Issue #2863904 by benjifisher: Typogrify does not handle langcode...
benjifisher’s picture

Status: Reviewed & tested by the community » Fixed

This is the first issue that I have fixed now that I am a maintainer.

wim leers’s picture

🥳 — thanks @benjifisher!

Status: Fixed » Closed (fixed)

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