Right now when a site setting is not created the tokens return "Setting not found". Could we consider returning nothing so the token can be used in conditional fields or other areas where the string might not be desired? I could provide a patch that removes the

else {
  return t('Setting not found');
}

from _site_settings_retrieve_deep_value but not sure if you'd like to keep it for backwards compatibility or not.

Comments

pavlosdan created an issue. See original summary.

pavlosdan’s picture

Here's a patch that removes the string from the tokens for now.

scott_euser’s picture

Status: Active » Needs work

Thanks for your contribution to this. I would be concerned about anyone having conditions on this and I think there is an argument for keeping it depending on how the site builder is using the module. I would prefer we add an alter hook or that we add it as an option to the configuration page so you could choose to change it but leaving the default as is.

Thanks,
Scott

pavlosdan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB

Hi Scott,

Thanks for your response. That makes sense!

Here's another patch that adds an alter hook to allow modules to alter/remove the string as needed while keeping the current one.

Please let me know your thoughts.

Thanks,
Pavlos

jwilson3’s picture

I was able to achieve what I needed with a small snippet of code, but it is definitely a bit hacky:

// In settings.php
$settings['locale_custom_strings_en'][''] = [
  // Ensure settings that are intentionally left empty are not rendered.
  'Setting not found' => '',
];

If this were to go in, I would want a bit more context in the alter hook, to be honest:

  1. to customize the empty token string value on a per-setting basis, ie, pass an argument to the alter hook with the site setting entity machine name.
  2. to customize the empty token string value on a field type and/or field name, and or site setting group basis, so that a fallback value could be specified appropriately in different cases; i.e. pass an argument to the alter hook with the token name being substituted, and ideally the field entity from the token as well.
  3. to customize the empty token string value using the default value specified in the field definition; ie pass an argument to the alter hook with the field definition. (I guess technically this could be loaded based by exploding the token name and loading the field name, so not required but definitely nice to have).

scott_euser’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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