When using tokens like [node:nid] in the prefix or suffix fields of a view mode controlled by Display Suite, it does not replace the tokens. There is a "Browse available tokens" selector link in the 'Expert' field template interface, suggesting that you should be able to use tokens. Tokens can be used in the custom DS fields, so there's workarounds available, but just wanted to know if this was by design or a bug.
Comment | File | Size | Author |
---|---|---|---|
#32 | ds_3x-2761767_32.patch | 4.28 KB | karenann |
#26 | ds_3x-2761767_26.patch | 4.27 KB | devarch |
#24 | interdiff_15_24.txt | 1.14 KB | rwam |
#24 | ds-prefix-suffix-tokens-3x-2761767-24.patch | 3.81 KB | rwam |
#20 | interdiff-2761767-14-20.txt | 654 bytes | loopduplicate |
Issue fork ds-2761767
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
aspilicious CreditAttribution: aspilicious commentedI need to test this that everything still works as expected.
I need to be sure the token replacements don't break allowed html tags.
Comment #3
Kristen PolThe patch did not work for me when using a prefix like:
but I changed the patch to make that work. The tokens need to be replaced first and then the text can be filtered.
I tested this with DS 8.x-3.0-rc1.
Comment #4
Kristen PolForgot the interdiff in the last comment so here it is.
Comment #5
Kristen PolWhoops. Diff'ed the wrong direction. Let's try that again.
Comment #6
aspilicious CreditAttribution: aspilicious commentedThis needs a test :)
Comment #7
aspilicious CreditAttribution: aspilicious commentedAdded a test
Comment #9
ippy CreditAttribution: ippy commentedKristen's patch in #3 applied and working on DS8.x-3.0 + D8.3.2
Thank you
Comment #10
loopduplicateThe patches in 3 and 7 no longer apply to the 8.x-2.x branch. They do apply to the 8.x-3.x branch. I did find a few issues with the patches but nothing critical.
Some duplicated code here.
The doc block title is not correct.
This should be updated to include a test for a token in the href attribute like mentioned in #3.
Here is a new patch against the 3.x branch and an interdiff between it an #7. I'll include a patch for the 2.x version next.
Comment #11
loopduplicateThis is the same logic as in #7 but without duplicated code.
This tests that the issue reported in #3 is resolved. Note that node:url:absolute was not used because that would require the contrib token module. The cause of the issue in #3 was core's filtering of allowed protocols in the href attribute, so testing for node:url is enough.
Comment #13
loopduplicateNote that tests will fail for #10 because the patch is for the 8.x-3.x version but I couldn't figure out how to mark it for testing against the 3.x version.
Comment #14
loopduplicateHere's a patch for the 2.x version.
Comment #15
loopduplicateHere's the same patch again as in #10 but marked to test against the 3.x version.
Comment #16
loopduplicateComment #18
loopduplicateHere's another patch for the 8.x-2.x branch which should pass testing.
Comment #20
loopduplicateAlright, here's one more attempt to get a passing test for the 8.x-2.x branch.
Comment #21
loopduplicateComment #22
aspilicious CreditAttribution: aspilicious commentedLooking good
Comment #23
rwam CreditAttribution: rwam commentedPatch in #15 doesn't work in a multilingual environment. So I've updated the patch for the 8.x-3.x branch to support translations too.
Comment #24
rwam CreditAttribution: rwam commentedPlease find attached updated patch to add multilingual support to the expert field template plugin.
Comment #25
devarch CreditAttribution: devarch as a volunteer commentedSome observations to #15 and #24
Do we need 'sanitize' => FALSE,? From the docs, there is no parameter with that name, the user is responsible for sanitizing the output.
The 'langcode' => \Drupal::languageManager()->getCurrentLanguage()->getId() can have a potential problem. From the docs getCurrentLanguage() without parameters defaults to \Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE, which is the current language of the interface not of the content, which in turn I don't think is the desired effect.
To get the actual content language the code block should look like:
with a
at the beginning of the .module file.
With these modifications everything works as expected.
Comment #26
devarch CreditAttribution: devarch as a volunteer commentedHere is the patch from #24 updated with the observations from #25 and fixed the 14 coding standard errors from the ds.module file, as reported by the phpcs --standard=Drupal.
Comment #27
karenann CreditAttribution: karenann as a volunteer commentedI have been using the patch in #15 successfully for a few months now.
However, recently, I found myself having to add multiple tokens to the "Suffix" field, as defined in ds/src/Plugin/DsFieldTemplate/Expert.php
While the suffix field in that template has a size declared, but no maxlength, I was finding a maxlength of 128 being applied to my Prefix and Suffix fields on that Expert template.
After some homework, I found file.settings.yml in my configuration:
If we commit the allowance of tokens in Prefix and Suffix, it may be prudent to consider a long maxlength ~or~ to convert those to a textarea in ds/src/Plugin/DsFieldTemplate/Expert.php.
Comment #28
devarch CreditAttribution: devarch as a volunteer commentedSo, is there any hope that this bug will be fixed? There are working patches attached, what's holding this?
Can someone from the DS developers have a look? It's almost three years since this bug was opened.
Comment #29
aspilicious CreditAttribution: aspilicious commentedFor the record, this is a feature request not a bug.
Comment #30
devarch CreditAttribution: devarch as a volunteer commented@aspilicious Since it gives you the option of browsing available tokens when customizing the field template, it clearly gives the message that you can use tokens in the prefix and suffix fields. Otherwise why would you browse those tokens?
If it was not an intended/supported behavior, you have to recognize that it's pretty confusing. More over the help message from prefix and suffix don't mention that tokens are not allowed/supported.
So either way this sounds more like a bug and not a feature request.
Leaving all this aside, even if it's a feature request, it is a very useful one, with solutions proposed and implemented (and tested in my case on live deploys) so the question remains: what's holding this back from being included in the release?
Comment #31
aspilicious CreditAttribution: aspilicious commentedThe test suite needs to be expanded with various test examples.
So yes you're right there is no comment that tokens are not allowed but that is easily added.
And comment #27 is completely ignored.
Setting to needs work for the tests.
Comment #32
karenann CreditAttribution: karenann as a volunteer commentedThe patch in #26 won't apply after 3.7.0 so I took a stab at rerolling it. I haven't tested functionality.
Comment #33
kungfu4 CreditAttribution: kungfu4 as a volunteer commentedHey all, applied patch from #32 and it seems to be working fine for me.
Thank you for this thread as it helped me solve my issues.
Comment #34
devkinetic CreditAttribution: devkinetic commentedThe new patch is great thank you! @karenann @aspilicious concerning #27, which is not directly related but VERY quickly becomes an issue once this patch lands, I have put together #3131480: Use a Textarea for Prefix and Suffix to address that.
Comment #35
chaloum CreditAttribution: chaloum commented#32. works. Thanks
Comment #36
swentel CreditAttribution: swentel at eps & kaas commentedWeirdly enough, while checking the queue and testing tokens in suffix and prefix, they already seem to work. There's a problem with multilingual content though, so will double check that.
Note: the dev branch now has an option to make prefix and suffix textareas, so that at least has been solved.
Comment #37
swentel CreditAttribution: swentel at eps & kaas commentedMoving to bug to make the fixes that are needed. Needs tests a volonte.
Comment #38
swentel CreditAttribution: swentel at eps & kaas commentedAdded related issue that added prefix/suffix support initially