Problem/Motivation

When a YAML form is referenced (for example by a node such as on a YAML form page as provided by the Yaml Form Node module), then the only display option is "YAML form" which embeds the form. There is no option to link to the dedicated URL of the form instead.

While displaying the form on a node page can be useful in many cases, it's not always an option for example when it's only one element on a page (such as link to contact form), or when access control to the form is needed (View permissions for nodes are only based on whether they are published, not by content type.)

Proposed resolution

Add a second display option that links to the dedicated URL of the form.

Remaining tasks

User interface changes

This is a UI change.

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ifrik created an issue. See original summary.

tuutti’s picture

FileSize
4.87 KB

I needed this as well, but eventually ended up going a different route.

Here is the initial patch if someone wants to continue working with this.

jrockowitz’s picture

It makes complete sense that in certain situations a link (instead of the form) to a YAML form from a node would make a lot of sense. The link should also include the source entity type and id (aka the YAML Form node) so that the submission can properly track this information.

For example, the link from the YAML Form node should be /form/contact?source_entity_type=node&source_entity_id=12345

The ability to populate a YAML Form submission source_entity should initially be limited to only valid YAML Form node, this would prevent end-users from injecting an unwanted source entity.

Once #2792681: Allow a YAML Form's source entity to be (optionally) populated using query string parameters. is done we should start working on the link formatter.

@tuutti The patch is good starting point, thanks

ifrik’s picture

Thanks a lot!
Adding the source entity ID to the link is in fact also part of the my own use case.

Displaying the referenced YAML form as a link to the referenced entity would also provide a practical solution for site builders to the access control issue raised in #2787121: YAML Form access control not being applied to YAML Form nodes.

ekes’s picture

Just looking at this for the first time, so thinking aloud, any pointers appreciated:

If you select 'Reference -> other' and then make an 'entity_reference' field to the YAML Form config entity, you have the default standard ID, Label, Rendered Entity FieldFormatters. Which includes the basic label link to the entity.

I assume the reason YAML form then implements it's own 'yamlform' FieldType is to add the schema for 'default_data' and 'status'. I'm guessing there are use cases where this should be related to the embedded Rendered Entity: embedding the same form multiple times as a rendered entity with differing defaults. And that there was no way of squeezing this data somewhere in the standard 'entity_reference' settings.

Core seem to generally implement FieldFormatters for 'entity_reference' but then restrict them to particular entity types with FormatterInterface::isApplicable().

So this could be both a FieldFormatter for 'entity_reference' and 'yamlform' extending EntityReferenceLabelFormatter adding in 'key'='[token:value]' (or something) query strings.
For 'entity_reference' it actually sounds like I generic module? My alternative thought, on the project only basis, here was it would be as quick to us 'entity_reference' with the Label FieldFormatter and just alter the output in some hook, or similar, on the way out.

jrockowitz’s picture

Status: Active » Needs review

So i just spent some time thinking about some other approaches and concluded that @tuutti's patch from #2 is the best solution. It allows a YAML form to be linked to from node teasers.

I was also able to get the 'default_data' to load correctly when a YAML Form is linked to with a valid source entity passed in the query string.

Let's see if the attach patch passes all the existing tests and then I have write some new tests.

@tuutti I also applied some of your code improvements to the YamlFormEntityReferenceEntityFormatter. Thanks again for the patch.

  • jrockowitz committed de58669 on 2792335-link-to-yamlform
    Issue #2792335: Link to dedicated URL as display option for referenced...
jrockowitz’s picture

Same patch + some tests.

Status: Needs review » Needs work

The last submitted patch, 8: link_to_dedicated_url-2792335-7.patch, failed testing.

  • jrockowitz committed da70717 on 2792335-link-to-yamlform
    Issue #2792335: Link to dedicated URL as display option for referenced...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
14.89 KB

  • jrockowitz committed 5f85d80 on 8.x-1.x
    Issue #2792335 by jrockowitz, tuutti, ifrik, ekes: Link to dedicated URL...
jrockowitz’s picture

Status: Needs review » Fixed

Tests are passing and there is no risk for data loss, so I committed the patch to 8.x-1.x.

Please checkout 8.x-1.x or download the dev release.

tuutti’s picture

Status: Fixed » Needs review
FileSize
1.33 KB

Sorry to nitpick, but you forgot to change YamlFormEntityReferenceEntityFormatter::__construct() comments to match the actual class.

  • jrockowitz committed fb27eba on 8.x-1.x authored by tuutti
    Issue #2792335 by jrockowitz, tuutti: Link to dedicated URL as display...
jrockowitz’s picture

Status: Needs review » Fixed

Absolutely not a nitpicky patch. Thanks.

ifrik’s picture

Thanks a lot for adding this so fast.
Together with the issue about adding the Source Entity ID, this covers what we needed.

Status: Fixed » Closed (fixed)

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