Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contact_storage-3403831
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
contact_storage-3403831
Commits
db6e47dc
Commit
db6e47dc
authored
8 years ago
by
Lee Rowlands
Committed by
Lee Rowlands
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2669794
by ultimike, jamadar, larowlan: Add ability to change the "Send message" button text
parent
a1f77e2c
No related branches found
Branches containing commit
Tags
8.x-1.0-beta3
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config/schema/contact_storage.schema.yml
+3
-0
3 additions, 0 deletions
config/schema/contact_storage.schema.yml
contact_storage.module
+26
-10
26 additions, 10 deletions
contact_storage.module
src/Tests/ContactStorageTest.php
+17
-8
17 additions, 8 deletions
src/Tests/ContactStorageTest.php
with
46 additions
and
18 deletions
config/schema/contact_storage.schema.yml
+
3
−
0
View file @
db6e47dc
...
...
@@ -8,3 +8,6 @@ contact.form.*.third_party.contact_storage:
submit_text
:
type
:
string
label
:
'
Submit
Text'
show_preview
:
type
:
boolean
label
:
'
Show
preview
button'
This diff is collapsed.
Click to expand it.
contact_storage.module
+
26
−
10
View file @
db6e47dc
...
...
@@ -5,6 +5,7 @@
* Contains main module logic.
*/
use
Drupal\contact\MessageForm
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Field\BaseFieldDefinition
;
...
...
@@ -19,19 +20,25 @@ use Drupal\contact\Entity\ContactForm;
function
contact_storage_form_contact_form_form_alter
(
&
$form
,
FormStateInterface
$form_state
)
{
/** @var \Drupal\contact\ContactFormInterface $contact_form */
$contact_form
=
$form_state
->
getFormObject
()
->
getEntity
();
$form
[
'contact_storage_uri'
]
=
array
(
$form
[
'contact_storage_uri'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Redirect Page'
),
'#description'
=>
t
(
'Input the Uri (entity:node/NODE-ID) of the Page to redirect the form after Submit.'
),
'#default_value'
=>
$contact_form
->
getThirdPartySetting
(
'contact_storage'
,
'redirect_uri'
,
FALSE
),
);
$form
[
'#entity_builders'
][]
=
'contact_storage_contact_form_form_builder'
;
$form
[
'contact_storage_submit_text'
]
=
array
(
];
$form
[
'contact_storage_submit_text'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
t
(
'Submit button text'
),
'#description'
=>
t
(
'
Override the submit button
\
's default
"
Send message
"
text.
'
),
'#description'
=>
t
(
"
Override the submit button's default
<em>
Send message
</em>
text.
"
),
'#default_value'
=>
$contact_form
->
getThirdPartySetting
(
'contact_storage'
,
'submit_text'
,
'Send message'
),
);
];
$form
[
'contact_storage_preview'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'Allow preview'
),
'#description'
=>
t
(
'Show the preview button?'
),
'#default_value'
=>
$contact_form
->
getThirdPartySetting
(
'contact_storage'
,
'show_preview'
,
TRUE
),
];
$form
[
'#entity_builders'
][]
=
'contact_storage_contact_form_form_builder'
;
}
/**
* Entity builder for the contact form edit form with third party options.
...
...
@@ -41,6 +48,7 @@ function contact_storage_form_contact_form_form_alter(&$form, FormStateInterface
function
contact_storage_contact_form_form_builder
(
$entity_type
,
ContactFormInterface
$contact_form
,
&
$form
,
FormStateInterface
$form_state
)
{
$contact_form
->
setThirdPartySetting
(
'contact_storage'
,
'redirect_uri'
,
$form_state
->
getValue
(
'contact_storage_uri'
));
$contact_form
->
setThirdPartySetting
(
'contact_storage'
,
'submit_text'
,
$form_state
->
getValue
(
'contact_storage_submit_text'
));
$contact_form
->
setThirdPartySetting
(
'contact_storage'
,
'show_preview'
,
$form_state
->
getValue
(
'contact_storage_preview'
));
}
/**
...
...
@@ -48,12 +56,20 @@ function contact_storage_contact_form_form_builder($entity_type, ContactFormInte
*/
function
contact_storage_form_contact_message_form_alter
(
&
$form
,
&
$form_state
,
$form_id
)
{
$form
[
'actions'
][
'submit'
][
'#submit'
][]
=
'contact_storage_contact_message_redirect_submit'
;
/** @var \Drupal\Core\Entity\ContentEntityForm $form_object */
$form_object
=
$form_state
->
getFormObject
();
/* @var \Drupal\contact\MessageInterface $contact_message */
$contact_message
=
$form_
state
->
getFormO
bject
()
->
getEntity
();
$contact_message
=
$form_
o
bject
->
getEntity
();
$contact_form
=
ContactForm
::
load
(
$contact_message
->
bundle
());
if
(
$submit_text
=
$contact_form
->
getThirdPartySetting
(
'contact_storage'
,
'submit_text'
,
FALSE
))
{
$form
[
'actions'
][
'submit'
][
'#value'
]
=
$submit_text
;
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_mode */
if
(
$form_object
instanceof
MessageForm
)
{
if
(
$submit_text
=
$contact_form
->
getThirdPartySetting
(
'contact_storage'
,
'submit_text'
,
FALSE
))
{
$form
[
'actions'
][
'submit'
][
'#value'
]
=
$submit_text
;
}
if
(
!
$contact_form
->
getThirdPartySetting
(
'contact_storage'
,
'show_preview'
,
TRUE
))
{
$form
[
'actions'
][
'preview'
][
'#access'
]
=
FALSE
;
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Tests/ContactStorageTest.php
+
17
−
8
View file @
db6e47dc
...
...
@@ -84,9 +84,9 @@ class ContactStorageTest extends ContactStorageTestBase {
// Click the view link and make sure name, subject and email are displayed
// by default.
$this
->
clickLink
(
t
(
'View'
));
foreach
(
$display_fields
as
$label
)
{
$this
->
assertText
(
$label
);
}
foreach
(
$display_fields
as
$label
)
{
$this
->
assertText
(
$label
);
}
// Make sure the stored message is correct.
$this
->
drupalGet
(
'admin/structure/contact/messages'
);
...
...
@@ -96,8 +96,9 @@ class ContactStorageTest extends ContactStorageTestBase {
$this
->
assertFieldById
(
'edit-subject-0-value'
,
'Test_subject'
);
$this
->
assertFieldById
(
'edit-message-0-value'
,
'Test_message'
);
// Submit should redirect back to listing.
$this
->
drupalPostForm
(
'admin/structure/contact/messages'
,
array
(),
$headers
=
array
(),
$form_html_id
=
NULL
,
t
(
'Save'
));
$this
->
assertUrl
(
'admin/structure/contact/messages'
,[]);
$this
->
drupalPostForm
(
NULL
,
array
(),
t
(
'Save'
));
$this
->
assertUrl
(
'admin/structure/contact/messages'
);
// Delete the message.
$this
->
clickLink
(
t
(
'Delete'
));
$this
->
drupalPostForm
(
NULL
,
NULL
,
t
(
'Delete'
));
...
...
@@ -120,14 +121,22 @@ class ContactStorageTest extends ContactStorageTestBase {
$this
->
assertText
(
'Your message has been sent.'
);
$this
->
assertEqual
(
$this
->
url
,
$admin_user
->
urlInfo
()
->
setAbsolute
()
->
toString
());
// Fill the "Submit button text" field and assert the form can still be submitted.
$edit
=
[
'contact_storage_submit_text'
=>
'Submit the form'
];
// Fill the "Submit button text" field and assert the form can still be
// submitted.
$edit
=
[
'contact_storage_submit_text'
=>
'Submit the form'
,
'contact_storage_preview'
=>
FALSE
,
];
$this
->
drupalPostForm
(
'admin/structure/contact/manage/test_id'
,
$edit
,
t
(
'Save'
));
$edit
=
[
'subject[0][value]'
=>
'Test subject'
,
'message[0][value]'
=>
'Test message'
,
];
$this
->
drupalPostForm
(
'contact'
,
$edit
,
t
(
'Submit the form'
));
$this
->
drupalGet
(
'contact'
);
$element
=
$this
->
cssSelect
(
'#edit-preview'
);
// Preview button is hidden.
$this
->
assertTrue
(
empty
(
$element
));
$this
->
drupalPostForm
(
NULL
,
$edit
,
t
(
'Submit the form'
));
$this
->
assertText
(
'Your message has been sent.'
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment