Problem/Motivation

The Preview button on the Contact form is displayed all the time even when the Manage Form Display has the Preview field setting set to Region Disabled.

Proposed resolution

Add a check to show the preview button conditionally obeying the Entity, Manage Form Display field settings.

Remaining tasks

None

User interface changes

None

API changes

None.

Data model changes

None.

Release notes snippet

None

Original report

In Drupal 8.5 (Theme Bartik), although I disabled in the UI the Preview button, in the UI, it still shows up in the contact form page.
Am I doing something wrong?

Comments

Manuel Ferreira created an issue. See original summary.

cilefen’s picture

Component: other » contact.module
alena_stanul’s picture

I investigated the problem. Really admin/structure/contact/manage/feedback/form-display we see 'Preview sender message'. After disabling in Manage display we see it in contact form. The same situation is for version Drupal 8.6.0-dev.
For display this button 'Preview' in Manage displays is responsible contact_entity_extra_field_info() in contact.module.

 $fields['contact_message'][$bundle]['form']['preview'] = [
      'label' => t('Preview sender message'),
      'description' => t('Preview'),
      'weight' => 40,
    ];

2 ways to solve the problem to not be confused:
1) to remove
$fields['contact_message'][$bundle]['form']['preview'] = [
'label' => t('Preview sender message'),
'description' => t('Preview'),
'weight' => 40,
];
2)to finish customization for this form element in Manage display.

alena_stanul’s picture

Status: Active » Needs work
alena_stanul’s picture

MrMason’s picture

I've moved the declaration of the preview button to inside the form() function instead of the actions() function.

cilefen’s picture

Status: Needs work » Needs review
Issue tags: -contact form
alena_stanul’s picture

I tested your patch. It works. But the code changes affected the location of the buttons(please see The effect of the patch on the location of the buttons.png).I wrote a new patch, that removes this effect and returns the buttons Send and Preview to one line.

alena_stanul’s picture

Status: Needs review » Needs work

The last submitted patch, 8: fixing_contact_preview_button_and_position-2960353-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

alena_stanul’s picture

MrMason’s picture

Alena,

The code you submitted overwrote the existing statements for the preview array element. Let me update this.

ckaotik’s picture

Status: Needs work » Needs review
StatusFileSize
new920 bytes

It's quite unusual to control action visibility with the form display mode.

How about this approach? It keeps the form actions in their separate section and simply checks the form display for its configuration.
The only thing I'm unsure about is whether the form_display object is always available in the form state. But I don't see why it shouldn't be there.

jidrone’s picture

I tested #13 in Drupal 8.5.3 and it worked.

borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This will need tests before it can go in.

mgstables’s picture

I used Patch from #13 in Drupal 8.5.4 and it worked.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ñull’s picture

#13 patched 8.6.10 correctly.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

honza pobořil’s picture

Patch #13 works with 8.7.2

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mherman-pro’s picture

Status: Needs work » Needs review

Patch #13 works with 8.8.1

Disabling "Preview sender message" in the form display removes the preview button from the contact form and re-enabling it restores it on the contact from and allows you to preview the message as normal. This was tested on the default contact form and a new form created with an added field.

opi’s picture

StatusFileSize
new569 bytes

Another approch using the #access key for the preview element, allowing contrib or custom code to still update this element.

mherman-pro’s picture

Patch #24 works with 8.8.1

I ran the same tests I detailed in post #23.

daften’s picture

Status: Needs review » Needs work

Just tested this, and it looks good, but as per #16, this still needs tests.

jaesperanza’s picture

Patches work on latest D8 to date, but until a patch has been committed, I will be using Hide Preview Button https://www.drupal.org/project/hide_preview works well for other form pages, too. In case, this helps those not comfortable with working with hooks and patches.

maxmendez’s picture

I've tested patch #23 on Drupal 8.8.5 and works as a charm.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

soaratul’s picture

Patch #13 works with 8.8.5

munish.kumar’s picture

Assigned: Unassigned » munish.kumar
munish.kumar’s picture

Hi,

Patch #24 looks good to me, I have tested this patch on drupal 9.x branch and it works as expected. here you will find the screenshots before and after apply patch.

munish.kumar’s picture

Assigned: munish.kumar » Unassigned
Status: Needs work » Needs review
pankaj.singh’s picture

Assigned: Unassigned » pankaj.singh
pankaj.singh’s picture

Assigned: pankaj.singh » Unassigned
StatusFileSize
new70.2 KB
new30.93 KB
new29.42 KB

Tested on 9.1.x
Patch Worked for me.

sivaji_ganesh_jojodae’s picture

Title: Remove Preview on Contact Forms » Make the Preview button on the Contact Forms to obey the "Manage form display" field settings
Issue summary: View changes
Issue tags: -Needs tests
StatusFileSize
new1.7 KB

Patch #24 with a test.

Status: Needs review » Needs work

The last submitted patch, 36: 2960353-36.patch, failed testing. View results

sivaji_ganesh_jojodae’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB
munish.kumar’s picture

StatusFileSize
new1.75 KB
new1020 bytes

Hi @DevJoJodae, I have reviewed your patch and found there are some deprecated code exists in your patch, So updating the patch accordingly and providing the interdiff for the same. See also https://www.drupal.org/node/3129738

pankaj.singh’s picture

Assigned: Unassigned » pankaj.singh
pankaj.singh’s picture

Assigned: pankaj.singh » Unassigned
StatusFileSize
new90.07 KB
new24.15 KB
new19.42 KB

Tested the patch given in #39. Patch worked for me.
Please refer the screeshots attached.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

bserem’s picture

Status: Needs review » Reviewed & tested by the community

#39 works for me too and also applies to D8 without problems.

  • catch committed eae5dcc on 9.2.x
    Issue #2960353 by alena_stanul, DevJoJodae, munish.kumar, MrMason,...

  • catch committed 4e38b9e on 9.1.x
    Issue #2960353 by alena_stanul, DevJoJodae, munish.kumar, MrMason,...
siramsay’s picture

RTBC

#39 works applied to 9.1.2

edit
See it was committed so that is good, thanks

catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

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