When adding the pattern for the entity label, there's a "Evaluate PHP in pattern" check box. Below the box, it says, "Put PHP code above that returns your string, but make sure you surround code in and . Note that $entity and $language are available and can be used by your code." I added a snippet like this:

<?php if ($language == 'fr') { // my code } else { // my other code } ?>

But it doesn't seem like $language is actually available. I saw the following error in the DB log:

"Notice: Undefined variable: language in eval() (line 1 of /app/web/modules/contrib/auto_entitylabel/src/AutoEntityLabelManager.php(338) ..."

Please let me know if this is a bug or if I have done something wrong.

Comments

andileco created an issue. See original summary.

waverate’s picture

This worked for me:

<?php switch('[node:langcode]') {
  case 'fr':
    return "Le ciel est [node:field_colour:entity]";
    break;
  default:
    return "The sky is [node:field_colour:entity]";
} ?>
colan’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
Component: Code » Documentation

My guess is that $language is an artifact from D7; it's probably not around anymore. Let's update the help text to talk about the token instead, unless there are better ideas.

deaom’s picture

This seem to not be a D8 version issue, as I can't seem to find the mentioned checkbox. Currently tokens are available as replacement patterns ([node:langcode] for example), so not sure where the updated text would go.

colan’s picture

Status: Active » Closed (outdated)