- Issue created by @Upchuk
Here's a quick patch that does this. So now the token can return a comma-separated list of values and EPP can explode them and set them onto the field.
- πΊπΈUnited States devkinetic
This module uses YAML encoding. I was able to get multiple values working out of the box using something like this:
$ids = [] foreach ($entity->get('field_foo')->getValue() as $x) { $ids[] = intval($x['target_id']); } $route_options['query']['foo'] = Yaml::dump($ids);
This will produce a url like
foo=-%208%0A-%209%0A
where 8 and 9 are the values. On the EPP side it callsnew Parser())->parse($yamlValue, ...);
where is transformed back into an array.The docs are severely lacking an example of how to do this. https://www.drupal.org/docs/contributed-modules/entity-prepopulate/entit... β only gives the hint of passing a one level array.
- πΈπ°Slovakia coaston
Hi devkinetic
It sounds good. Would you be able to provide a patch?
- πΊπΈUnited States devkinetic
I'm not sure exactly what you mean, there is nothing to patch on the UI side. My reply really only explains how properly construct your URLs. In the case of multivalue, you need to do something like this if your building your url from code:
// each integer is a entity target_id on the multivalue field $x = [1, 2, 3]; Yaml::dump($x);
Which will produce the following YAML:
- 1 - 2 - 3
This can then be added as your query parameter, making the value of the token a urlencoded YAML string.
If your building your URL manually, you can do
/node/add/article?field_multivalue=-%208%0A-%209%0A
where the format isdash space VALUE newline dash space VALUE
. - π©π°Denmark ressa Copenhagen
Thanks @upchuck, being able to prepopulate multiple fields and documentation on how to do it would be fantastic. Specifically, I am trying to prepopulate a single node with multiple addresses, using the Address module, filling out just the "Street address" (called "Address line 1"/
address_line1
in the configuration) and "Country" fields. For example:- Tailor Street 23, UK
- Baker Street 42, UK
etc.
It would be great with having the feature, but also how to actually target the fields, like the "0" in
[node:field_location:0:address_line1]
probably needs to be something else, right?Also, how would you configure EPP to pick up tokens under an Address field type? There is only a single shared "Entity Prepopulate" field, but multiple fields (or they are called "properties") such as "First name", "Middle name", etc.
Thanks!
- π©π°Denmark ressa Copenhagen
I tried the patch from #2. It works well, and I can prepopulate multiple fields via an URL such as
/node/add/article?Body=24&multi=first value,second value
in a multivalue field.I re-created the patch as a Gitlab MR, in case it can help get this great feature committed.
- π©π°Denmark ressa Copenhagen
Values can often have commas in them, so perhaps another separator such as pipe ("|") might be better? I have created an alternative suggestion which uses pipe as separator: 3387774-multivalues-from-token-pipe-separator.