Adding a view_builder to contact form allows us to "render entity" in entity reference which allows form to be embedded basically anywhere, which is awesome.

Eclipse

Comments

EclipseGc created an issue. See original summary.

eclipsegc’s picture

StatusFileSize
new3.93 KB

code!

andypost’s picture

Status: Active » Needs work

Why not use a block for that?

  1. +++ b/src/ContactFormViewBuilder.php
    @@ -0,0 +1,118 @@
    +
    +class ContactFormViewBuilder extends EntityViewBuilder {
    

    needs doc block

  2. +++ b/src/ContactFormViewBuilder.php
    @@ -0,0 +1,118 @@
    +  protected function entityFormBuilder() {
    ...
    +  protected function getRenderer() {
    ...
    +  protected function config($name) {
    ...
    +  private function container() {
    

    Why? this is a EntityViewBuilder so createInstance() could pass deps

eclipsegc’s picture

StatusFileSize
new3.97 KB

Because block is just one of many options if we take this approach. Having a view builder on the contact form entity makes a ton of sense and allows us to essentially create custom node types that are contact forms, custom block types as well, or really any fieldable entity can use a contact form reliably now. It also means that contact forms are re-usable in various situations so if you create a contact form add it to a node, and eventually unpublish that node, you don't need to re-create the contact form, just add it to another node and it'll keep collecting data appropriately.

Eclipse

andypost’s picture

Status: Needs work » Needs review

Makes a lot of sense

andypost’s picture

Makes a lot of sense

andypost’s picture

Issue tags: +Needs tests
tim.plunkett’s picture

StatusFileSize
new4.82 KB
new5.39 KB

Since you're overriding view completely and not calling parent, you need to do the same for viewMultiple.
And at that point, you don't need the rest of the parent class, and it's all useless.

larowlan’s picture

Looks good, just needs a test - thanks!

davidwbarratt’s picture

Status: Needs review » Needs work

I'm getting this error with the patch from #8:

The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Argument 1 passed to Drupal\contact_storage\ContactFormViewBuilder::__construct() must be an instance of Drupal\Core\Entity\EntityFormBuilderInterface, instance of Drupal\Core\Config\Entity\ConfigEntityType given, called in core/lib/Drupal/Core/Entity/EntityTypeManager.php on line 254 and defined in Drupal\contact_storage\ContactFormViewBuilder->__construct() (line 68 of modules/contrib/contact_storage/src/ContactFormViewBuilder.php). 
davidwbarratt’s picture

Status: Needs work » Needs review

The patch from #2 works perfectly.

tim.plunkett’s picture

StatusFileSize
new4.89 KB
new756 bytes

Needs tests indeed :)

davidwbarratt’s picture

Patch in #12 worked perfectly for me, but I'll leave the status since we still need tests (#9).

podarok’s picture

#12 works for me as well
Tested with entity_embed and contact form easily embedded via wysiwyg button.
Cool

emanuelrighetto’s picture

I can confirm that #12 works like a charm.

Thank you guys.

larowlan’s picture

We still need tests here

naveenvalecha’s picture

Issue tags: -Needs tests
StatusFileSize
new9.9 KB
new5.01 KB

Added webtest for checking whether the contact form is showing. Can we write kerneltest case(will take less time to run) for checking view builder.

larowlan’s picture

Status: Needs review » Fixed
StatusFileSize
new12.88 KB
new13.6 KB

Committed with the attached cleanup

naveenvalecha’s picture

Status: Fixed » Needs work

patch has not yet pushed to repo

  • larowlan committed b12255d on 8.x-1.x authored by EclipseGc
    Issue #2615112 by tim.plunkett, EclipseGc, naveenvalecha: Add a view...
  • larowlan committed ca90e67 on 8.x-1.x
    Issue #2615112 by tim.plunkett, EclipseGc, naveenvalecha, larowlan: Add...
larowlan’s picture

Status: Needs work » Fixed

oh, didn't merge - but was pushed to a branch - checking the release now

larowlan’s picture

release is fine

Status: Fixed » Closed (fixed)

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

Strutsagget’s picture

So how do i use this?
Can't find anywhere where to add for example as a block.

eclipsegc’s picture

Add an entity reference field to a custom block type and reference the contact_form entity type. Then you can add any contact form you've created to a block by simply referencing it. Be sure to set the reference's display to render the full entity.

Eclipse

mvdve’s picture

You can also install the drupal 8 version of Ctools. It provides a handy entity_view block which you can use everywhere (blocks, panels, pagemanager etc).

This functionality should be added to the project page, love it!

andypost’s picture

dianacastillo’s picture

I'm tryinng this with entity embed and it does not give me the option to view the entire contact form, only id or link