- Issue created by @caesius
- πΊπΈUnited States caesius
Since I figure it'll be asked, the WSOD was:
TypeError: Drupal\site_settings\Plugin\SiteSettingsLoader\FlattenedSiteSettingsLoader::renderDefault(): Return value must be of type Drupal\Component\Render\MarkupInterface, string returned in Drupal\site_settings\Plugin\SiteSettingsLoader\FlattenedSiteSettingsLoader->renderDefault() (line 488 of modules/contrib/site_settings/src/Plugin/SiteSettingsLoader/FlattenedSiteSettingsLoader.php).
And I did go through the update workflow (updb etc.)
Again, it works with the Full loader, which seems to be the "more correct" and forward-compatible method anyway, but it seems to be lacking utility functions outside of Twig (unless I overlooked something obvious)
- π¬π§United Kingdom scott_euser
In the latest version as a result of https://www.drupal.org/project/site_settings/issues/3498435 β¨ Add developer helptext (when access available) to output some site settings via twig Active (2.0.1 onwards) you should see copy-pasteable twig snippets throughout the UI to be able to output values from the full loader. These snippets match the examples on the module homepage. They are found where site settings are configured (admin structure rather than admin content area)
Still we should fix the fatal error as well though so will leave this open.
- πΊπΈUnited States caesius
I don't have the option of using twig since I'm using an access hook in a module. When I do use twig the helptext works great, but it's not applicable here. There's no utility functions to simplify or navigate the structure of the site settings that are brought in through
loadAll()
(that I could find, anyway)If I find steps to reproduce for the WSOD I'll split off a new issue.
- π¬π§United Kingdom scott_euser
Ah okay, in that case of you look in the module source code you could copy how fields are rendered from the twig functions in your own code, e.g. https://git.drupalcode.org/project/site_settings/-/blob/2.0.x/src/Twig/T...
But ultimately Stie Settings are just field able entities like Nodes or Terms so getting a field value is the same, e.g. $entity->field_name->value.
- πΊπΈUnited States caesius
Thanks!
For the record, this is what I came up with:
$site_settings = \Drupal::service('site_settings.loader'); $settings = $site_settings->loadAll(); $scholar_ledger_path = $settings['scholar_ledger']['scholar_ledger_path_alias'];
became
$setting = \Drupal::entityTypeManager()->getStorage('site_setting_entity') ->loadByProperties(['type' => 'scholar_ledger_path_alias']); $scholar_ledger_path = reset($setting) ->get('field_settings_text') ->getString();
But now I'm not sure in what context I'd need to use the site settings loader instead...
Anyway, this issue can probably be closed, unless there's maybe a documentation issue that wasn't considered? I only laser-focused on trying to use the site settings loader instead of following the TwigExtension.php examples because that's what the project page said to use.