3

Is there a way for a Paragraph to reference either a custom Form (built with Form API) or a block plugin that renders the same form? I only see a way to have a field that references either custom blocks (content) or configuration blocks, but not both. How can this scenario be solved?

3

I haven't tried it, but the Dynamic Entity Reference module looks good. The 8.x-2.x branch, although currently in alpha, sounds like it has the functionality you're looking for:

This version allows all content entities as referenceable entities. This version also allows all config entities as referenceable entities but it is only configurable programmatically. The content and config entities can be referenced in the same field as well.

It'll mean a bit of coding to get the config entity working, but a lot less code than writing the whole thing from scratch.

  • Having re-read the question I'm not sure I've addressed the right thing, I was concentrating on the I only see a way to have a field that references either custom blocks (content) or configuration blocks, but not both, which hopefully the mentioned module would solve. If this isn't what you meant let me know and I'll delete it – Clive Dec 13 '17 at 20:22
  • It could be? Basically I wanted to reference a form I made, which doesn't seem available via ERR, neither is the block I made to output it. The form I can see not being an option, but I would think a block would be. But then, you're left with a Configuration reference for the field, giving authors way too many options than needed. – Kevin Dec 13 '17 at 20:50
  • @Clive + Kevin, nice hats by the way. This module would indeed be a bit heavy weight to integrate a custom form. You only need one line of code calling FormBuilder::getForm() in a hook_paragraph_view(). To make this configurable a poor man solution would be a string field with the class name (or part of it) and then replace the build of this field with the form. Or make it a bit nicer with an autocomplete field or something like webform does for the node integration. – 4k4 Dec 13 '17 at 20:55
  • Yeah for right now I did a preprocess, and injected the form as a variable to the template. – Kevin Dec 13 '17 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.