We've created setting types with multiple fields - example: Company Contact Data.
The goal was to print out the whole entity like:
[site_settings:contact--contact:rendered:teaser]
[site_settings:contact--contact:0:rendered:teaser]
So we are able to use the template file (or maybe layout builder) to structure it + have different view modes - in other words: The full power of entities ;)
Currently the token browser just shows up the single fields of the entity.
| Comment | File | Size | Author |
|---|
Issue fork site_settings-3067325
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodywell that absolutely makes sense and would improve this module a lot. I guess that something similar already exists through token.tokens.inc general entity implementations like:
and
So we could use a lot of that code but provide it globally and not just in the context of the entity.
The rendered entity could be retrieved like this for example, but I guess token.tokens.inc has a better solution...
Comment #3
scott_euser commentedI wonder if this would have performance impacts given settings are passed to all templates.
A possible prerequisite for this:
https://www.drupal.org/project/site_settings/issues/2945236
I otherwise like the idea of token instead of full render array so it is 'on demand' rather than default:
https://www.drupal.org/project/site_settings/issues/3021720
Comment #4
anybodyThank you @scott_euser,
I absolutely agree. The current tokens should stay of course, we could simply add the new ones. I think there are already solutions for these kind of tokens in other modules and of course they should be lazy-loaded, perhaps through not yet rendered render arrays.
I hope we or someone else will find the time for this soon, but we're very busy, like everyone...
As I saw the patch in comment #7 of #2943440: How to get rendered value of Site Settings formatted text field in token? does a huge part of the job already, but renders in hook_tokens, which might cause performance problems?
Comment #5
scott_euser commentedIn terms of just using the site setting entity directly as a token, this seemed to work fine for me in a form controller or a form alter:
Comment #8
dieterholvoet commentedI added tokens exposing all site settings entities and their fields.
Comment #9
dieterholvoet commentedHere's a patch of the current state of the MR for easy inclusion in projects.
Comment #10
anybodyOr as dynamic patch: https://git.drupalcode.org/project/site_settings/-/merge_requests/3.diff
@scott_euser how to proceed here?
Comment #11
scott_euser commentedThanks both! I think we just need a method added to https://git.drupalcode.org/project/site_settings/-/blob/8.x-1.x/tests/sr... to avoid regression on this in the future. Otherwise looks good! I'll give this a final manual test as well once we have the automated test in place.
Comment #12
dieterholvoet commentedComment #13
dieterholvoet commentedI added a test but it's failing because of the token module dependency missing. I don't really understand why, I added it to test_dependencies.
Comment #14
scott_euser commentedApologies for the delay in getting to this. I have been running the tests locally and getting:
It's the $has_index bit here, but I am struggling to understand what the preg_match is attempting to achieve. Is it possible to put some additional comments in with examples of what we are trying to find, and why we need ($index - 1) into here.
In the meantime I have been doing some coding standards and deprecations fixing on the module itself, updated patch as is with these coding standards and deprecations fixes to within the patch.
Comment #15
anybodyThank you very much @scoot_euser! In the meantime, we switched to the "config_pages" module for this task as it better fitted our needs. Perhaps @DieterHolvoet can help.
Thanks and sorry.
Comment #16
dieterholvoet commentedComment #17
scott_euser commentedMerged latest into the merge request. Same test failure though as in #16. Thanks for the progress on this and apologies for the silence!
Comment #18
scott_euser commentedI added the test_dependency to the 2.0.x branch as, looking at other contrib modules like here, it is the only way to get past that bit of the test failure in order to see true test failures like you would if running locally. Ie, we should now see the test failure from my comment above.
Comment #19
scott_euser commentedSome phpcs/phpstan issues also flagged.
Comment #21
scott_euser commentedOkay finally got around to this, thanks everyone!