Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mailchimp
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
mailchimp
Merge requests
!20
WIP - Resolve
#3189464
"Integrate with custom"
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
WIP - Resolve
#3189464
"Integrate with custom"
3189464-integrate-with-custom
into
2.x
Overview
1
Commits
51
Pipelines
0
Changes
26
Merged
WIP - Resolve #3189464 "Integrate with custom"
Maria Fisher
requested to merge
3189464-integrate-with-custom
into
2.x
May 13, 2021
Overview
1
Commits
51
Pipelines
0
Changes
26
Closes
#3189464
- not ready to merge
0
0
Merge request reports
Compare
2.x
version 20
c6e5e88c
Jul 13, 2021
version 19
d76d4639
Jun 3, 2021
version 18
89ea3f70
Jun 2, 2021
version 17
6af4f98a
May 15, 2021
version 16
66e305e8
May 15, 2021
version 15
17bbd2b2
May 14, 2021
version 14
473a4442
May 14, 2021
version 13
831b15df
May 14, 2021
version 12
db1b67a5
May 14, 2021
version 11
d57d0d95
May 14, 2021
version 10
710c99dd
May 14, 2021
version 9
40112b3b
May 14, 2021
version 8
58c7a2a3
May 14, 2021
version 7
42a2b4e9
May 14, 2021
version 6
4bb19c53
May 14, 2021
version 5
cfbfc0f6
May 14, 2021
version 4
e11c6eee
May 14, 2021
version 3
e6080c68
May 14, 2021
version 2
aaf79def
May 14, 2021
version 1
4aa12886
May 13, 2021
2.x (base)
and
latest version
latest version
c6e5e88c
51 commits,
Jul 13, 2021
version 20
c6e5e88c
51 commits,
Jul 13, 2021
version 19
d76d4639
51 commits,
Jun 3, 2021
version 18
89ea3f70
50 commits,
Jun 2, 2021
version 17
6af4f98a
48 commits,
May 15, 2021
version 16
66e305e8
47 commits,
May 15, 2021
version 15
17bbd2b2
45 commits,
May 14, 2021
version 14
473a4442
44 commits,
May 14, 2021
version 13
831b15df
43 commits,
May 14, 2021
version 12
db1b67a5
42 commits,
May 14, 2021
version 11
d57d0d95
41 commits,
May 14, 2021
version 10
710c99dd
39 commits,
May 14, 2021
version 9
40112b3b
38 commits,
May 14, 2021
version 8
58c7a2a3
37 commits,
May 14, 2021
version 7
42a2b4e9
36 commits,
May 14, 2021
version 6
4bb19c53
35 commits,
May 14, 2021
version 5
cfbfc0f6
34 commits,
May 14, 2021
version 4
e11c6eee
31 commits,
May 14, 2021
version 3
e6080c68
29 commits,
May 14, 2021
version 2
aaf79def
28 commits,
May 14, 2021
version 1
4aa12886
27 commits,
May 13, 2021
26 files
+
1647
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
26
modules/mailchimp_events/modules/mailchimp_events_example/src/Form/AddMailchimpEvent.php
0 → 100644
+
151
−
0
View file @ c6e5e88c
Edit in single-file editor
Open in Web IDE
<?php
namespace
Drupal\mailchimp_events_example\Form
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Link
;
use
Drupal\Core\Url
;
use
Drupal\mailchimp_events
\Entity\MailchimpEvent
;
use
Laminas\Diactoros\Response\RedirectResponse
;
/**
* A sample form for adding a Mailchimp Event.
*/
class
AddMailchimpEvent
extends
FormBase
{
/**
* {@inheritdoc}
*/
public
function
getFormId
()
{
return
'add_mailchimp_event'
;
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'description'
][
'#markup'
]
=
$this
->
t
(
'Cause an event to occur now, for a specific audience member in Mailchimp.'
);
$add_link
=
Link
::
createFromRoute
(
'You can add event types here.'
,
'entity.mailchimp_event.add_form'
,
[],
[
'attributes'
=>
[
'target'
=>
'_blank'
]]
);
$mc_lists
=
mailchimp_get_lists
();
$list_options
=
[];
foreach
(
$mc_lists
as
$key
=>
$value
)
{
$list_options
[
$key
]
=
$value
->
name
;
}
$events
=
MailchimpEvent
::
loadMultiple
();
$event_options
=
[];
if
(
empty
(
$events
))
{
$this
->
messenger
()
->
addError
(
$this
->
t
(
'At least one event type is required. @add-link'
,[
'@add-link'
=>
$add_link
->
toString
(),
]));
return
$form
;
}
else
{
foreach
(
$events
as
$key
=>
$event
)
{
$event_options
[
$event
->
getName
()]
=
$event
->
getName
();
}
}
$form
[
'list'
]
=
[
'#type'
=>
'select'
,
'#title'
=>
$this
->
t
(
'Mailchimp audience'
),
'#weight'
=>
'0'
,
'#required'
=>
TRUE
,
'#options'
=>
$list_options
,
];
$form
[
'email'
]
=
[
'#type'
=>
'email'
,
'#title'
=>
$this
->
t
(
'Email'
),
'#description'
=>
$this
->
t
(
'The email address to associate with this event.'
),
'#weight'
=>
'0'
,
'#required'
=>
TRUE
,
];
$form
[
'event_name'
]
=
[
'#type'
=>
'select'
,
'#title'
=>
$this
->
t
(
'Event Name'
),
'#description'
=>
$this
->
t
(
'The name of the Event. %add_link'
,
[
'%add_link'
=>
$add_link
->
toString
()]),
'#weight'
=>
'0'
,
'#required'
=>
TRUE
,
'#options'
=>
$event_options
,
];
$form
[
'event_value'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Event value'
),
'#description'
=>
$this
->
t
(
'This can be any string.'
),
'#maxlength'
=>
64
,
'#size'
=>
64
,
'#weight'
=>
'0'
,
'#required'
=>
TRUE
,
];
$form
[
'is_syncing'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Is Syncing?'
),
'#description'
=>
$this
->
t
(
'Events created with the is_syncing value set to true will not trigger automations.'
),
];
$form
[
'occurred_at'
]
=
[
'#type'
=>
'datetime'
,
'#description'
=>
$this
->
t
(
'The date and time the event occurred. Defaults to the time when the form loaded.'
),
'#title'
=>
$this
->
t
(
'Occurred at'
),
'#size'
=>
20
,
'#date_time_format'
=>
'H:i'
,
'#default_value'
=>
DrupalDateTime
::
createFromTimestamp
(
time
()),
];
$form
[
'submit'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
$this
->
t
(
'Submit'
),
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$email
=
$form_state
->
getValue
(
'email'
);
$list
=
$form_state
->
getValue
(
'list'
);
$properties
=
[
'value'
=>
$form_state
->
getValue
(
'event_value'
),
'another_property'
=>
'Always the same!'
,
];
$event_name
=
$form_state
->
getValue
(
'event_name'
);
$occurred_at
=
$form_state
->
getValue
(
'occurred_at'
)
->
getTimestamp
();
$is_syncing
=
$form_state
->
getValue
(
'is_syncing'
);
$result
=
mailchimp_events_add_member_event
(
$list
,
$email
,
$event_name
,
$properties
,
$is_syncing
,
$occurred_at
);
$debug
=
$this
->
t
(
"Called function: mailchimp_events_add_member_event(%list, %email, %event_name, %properties, %is_syncing, %occurred_at)."
,
[
'%list'
=>
$list
,
'%email'
=>
$email
,
'%event_name'
=>
$event_name
,
'%properties'
=>
print_r
(
$properties
,
TRUE
),
'%is_syncing'
=>
$is_syncing
,
'%occurred_at'
=>
$occurred_at
,
]);
if
(
$result
!==
FALSE
)
{
$this
->
messenger
()
->
addStatus
(
$debug
);
}
else
{
$this
->
messenger
()
->
addError
(
$debug
);
$this
->
messenger
()
->
addError
(
$this
->
t
(
'No results returned. Check the <a href=":watchdog">logs for Mailchimp</a>'
,
[
':watchdog'
=>
Url
::
fromRoute
(
'dblog.overview'
)
->
toString
()]));
}
}
}
Loading