Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rng
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
rng
Commits
8b892668
Commit
8b892668
authored
9 years ago
by
dpi
Browse files
Options
Downloads
Patches
Plain Diff
Added support for new Courier template collection list element.
Creating a message will now redirect back to message list.
parent
0d38643b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Form/MessageActionForm.php
+5
-2
5 additions, 2 deletions
src/Form/MessageActionForm.php
src/Form/MessageListForm.php
+154
-82
154 additions, 82 deletions
src/Form/MessageListForm.php
with
159 additions
and
84 deletions
src/Form/MessageActionForm.php
+
5
−
2
View file @
8b892668
...
@@ -103,7 +103,7 @@ class MessageActionForm extends FormBase {
...
@@ -103,7 +103,7 @@ class MessageActionForm extends FormBase {
$form
[
'actions'
]
=
array
(
'#type'
=>
'actions'
);
$form
[
'actions'
]
=
array
(
'#type'
=>
'actions'
);
$form
[
'actions'
][
'submit'
]
=
array
(
$form
[
'actions'
][
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#type'
=>
'submit'
,
'#value'
=>
t
(
'
Add
message
and edit templates
'
),
'#value'
=>
t
(
'
Create
message'
),
);
);
$form
[
'actions'
][
'cancel'
]
=
array
(
$form
[
'actions'
][
'cancel'
]
=
array
(
'#type'
=>
'link'
,
'#type'
=>
'link'
,
...
@@ -167,7 +167,10 @@ class MessageActionForm extends FormBase {
...
@@ -167,7 +167,10 @@ class MessageActionForm extends FormBase {
$rule_component
->
save
();
$rule_component
->
save
();
}
}
$form_state
->
setRedirectUrl
(
$action
->
urlInfo
(
'edit-form'
));
$entity_type
=
$event
->
getEntityTypeId
();
$form_state
->
setRedirectUrl
(
Url
::
fromRoute
(
'rng.event.'
.
$entity_type
.
'.messages'
,
[
$entity_type
=>
$event
->
id
(),
]));
}
}
}
}
This diff is collapsed.
Click to expand it.
src/Form/MessageListForm.php
+
154
−
82
View file @
8b892668
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
Drupal\rng\Form
;
namespace
Drupal\rng\Form
;
use
Drupal\Core\Routing\RedirectDestinationInterface
;
use
Drupal\Core\Routing\RedirectDestinationInterface
;
use
Drupal\courier\Entity\TemplateCollection
;
use
Drupal\rng\EventManagerInterface
;
use
Drupal\rng\EventManagerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\FormStateInterface
;
...
@@ -15,6 +16,7 @@ use Drupal\Core\Form\FormBase;
...
@@ -15,6 +16,7 @@ use Drupal\Core\Form\FormBase;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\rng\Plugin\Condition\CurrentTime
;
use
Drupal\rng\Plugin\Condition\CurrentTime
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\rng\RuleInterface
;
/**
/**
* Creates message list form.
* Creates message list form.
...
@@ -99,113 +101,183 @@ class MessageListForm extends FormBase {
...
@@ -99,113 +101,183 @@ class MessageListForm extends FormBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
,
RouteMatchInterface
$route_match
=
NULL
,
$event
=
NULL
)
{
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
,
RouteMatchInterface
$route_match
=
NULL
,
$event
=
NULL
)
{
$header
=
[
$form
[
'#rng_event'
]
=
$route_match
->
getParameter
(
$event
);
$this
->
t
(
'Trigger'
),
$this
->
t
(
'Date'
),
// @todo: move trigger definitions to a discovery service.
[
$rng_triggers
=
[
'data'
=>
$this
->
t
(
'Enabled'
),
'entity:registration:new'
=>
$this
->
t
(
'Registration creation'
),
'class'
=>
[
'checkbox'
],
'entity:registration:update'
=>
$this
->
t
(
'Registration updated'
),
'rng:custom:date'
=>
$this
->
t
(
'Send on a date'
),
];
// Actions.
$form
[
'actions'
]
=
[
'#type'
=>
'details'
,
'#attributes'
=>
[
'class'
=>
[
'container-inline'
],
],
'#open'
=>
TRUE
,
];
$form
[
'actions'
][
'operation'
]
=
[
'#title'
=>
$this
->
t
(
'With selection'
),
'#type'
=>
'select'
,
'#options'
=>
[
'enable'
=>
$this
->
t
(
'Enable messages'
),
'disable'
=>
$this
->
t
(
'Disable messages'
),
'delete'
=>
$this
->
t
(
'Delete messages'
),
],
],
$this
->
t
(
'Operations'
),
'#empty_option'
=>
$this
->
t
(
' - Select - '
),
'#button_type'
=>
'primary'
,
];
];
$form
[
'action_list'
]
=
[
$form
[
'actions'
][
'enable'
]
=
[
'#type'
=>
'table'
,
'#type'
=>
'submit'
,
'#header'
=>
$header
,
'#value'
=>
$this
->
t
(
'Save'
),
'#title'
=>
$this
->
t
(
'Messages'
),
'#button_type'
=>
'primary'
,
'#empty'
=>
$this
->
t
(
'No messages found for this event.'
),
];
];
$rng_triggers
=
[
// List items.
'entity:registration:new'
=>
$this
->
t
(
'When registrations are created.'
),
$form
[
'list'
]
=
[
'entity:registration:update'
=>
$this
->
t
(
'When registrations are updated.'
),
'#type'
=>
'courier_template_collection_list'
,
'rng:custom:date'
=>
$this
->
t
(
'Current date is after a date.'
),
'#checkboxes'
=>
TRUE
,
'#items'
=>
[],
];
];
$destination
=
$this
->
redirectDestination
->
getAsArray
();
$form
[
'#rng_event'
]
=
$route_match
->
getParameter
(
$event
);
foreach
(
$this
->
getCommunicationRules
(
$form
[
'#rng_event'
])
as
$rid
=>
$rule
)
{
foreach
(
$this
->
getCommunicationRules
(
$form
[
'#rng_event'
])
as
$rid
=>
$rule
)
{
foreach
(
$rule
->
getActions
()
as
$action
)
{
$trigger_id
=
$rule
->
getTriggerID
();
$row
=
[];
if
(
$template_collection
=
$this
->
getTemplateCollectionForRule
(
$rule
))
{
$links
=
[];
// Add description for date conditions.
// @todo: move trigger definitions to a discovery service.
$description
=
NULL
;
$trigger_id
=
$rule
->
getTriggerID
();
if
(
$component
=
$this
->
getDateCondition
(
$rule
))
{
$row
[
'trigger'
][
'#markup'
]
=
isset
(
$rng_triggers
[
$trigger_id
])
?
$rng_triggers
[
$trigger_id
]
:
$trigger_id
;
$row
[
'date'
][
'#markup'
]
=
$this
->
t
(
'N/A'
);
foreach
(
$rule
->
getConditions
()
as
$component
)
{
$condition
=
$component
->
createInstance
();
$condition
=
$component
->
createInstance
();
if
(
$condition
instanceof
CurrentTime
)
{
$description
=
$condition
->
getDateFormatted
();
$row
[
'date'
][
'#markup'
]
=
$condition
->
getDateFormatted
();
if
(
$component
->
access
(
'edit'
))
{
$links
[
'edit-date'
]
=
[
'title'
=>
$this
->
t
(
'Edit date'
),
'url'
=>
$component
->
urlInfo
(
'edit-form'
),
'query'
=>
$destination
,
];
}
}
}
}
$row
[
'status'
]
=
[
$form
[
'list'
][
'#items'
][
$rule
->
id
()]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'@label (@status)'
,
[
'#title'
=>
$this
->
t
(
'Active'
),
'@label'
=>
isset
(
$rng_triggers
[
$trigger_id
])
?
$rng_triggers
[
$trigger_id
]
:
$trigger_id
,
'#title_display'
=>
'invisible'
,
'@status'
=>
$rule
->
isActive
()
?
$this
->
t
(
'active'
)
:
$this
->
t
(
'disabled'
),
'#default_value'
=>
(
bool
)
$rule
->
isActive
(),
]),
'#wrapper_attributes'
=>
[
'#description'
=>
$description
,
'class'
=>
[
'#template_collection'
=>
$template_collection
,
'checkbox'
,
'#operations'
=>
$this
->
getOperations
(
$rule
),
],
],
];
];
}
}
if
(
$action
->
access
(
'edit'
))
{
return
$form
;
$links
[
'edit-templates'
]
=
[
}
'title'
=>
$this
->
t
(
'Edit templates'
),
'url'
=>
$action
->
urlInfo
(
'edit-form'
),
'query'
=>
$destination
,
];
}
if
(
$rule
->
access
(
'delete'
))
{
$links
[
'delete'
]
=
[
'title'
=>
$this
->
t
(
'Delete'
),
'url'
=>
$rule
->
urlInfo
(
'delete-form'
),
'query'
=>
$destination
,
];
}
$row
[
'operations'
][
'data'
]
=
[
/**
'#type'
=>
'operations'
,
* {@inheritdoc}
'#links'
=>
$links
,
*/
];
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$message
=
NULL
;
$operation
=
$form_state
->
getValue
([
'operation'
]);
// Checkbox is checked, keyed by rule ID.
$checkbox
=
$form_state
->
getValue
([
'list'
,
'checkboxes'
]);
$form
[
'action_list'
][
$rid
]
=
$row
;
// A list of checked rules.
$rules
=
[];
foreach
(
$this
->
getCommunicationRules
(
$form
[
'#rng_event'
])
as
$rule
)
{
// Checkbox is checked.
if
(
$checkbox
[
$rule
->
id
()])
{
$rules
[]
=
$rule
;
}
}
}
}
$form
[
'actions'
]
=
[
'#type'
=>
'actions'
];
/** @var RuleInterface $rule */
$form
[
'actions'
][
'submit'
]
=
[
foreach
(
$rules
as
$rule
)
{
'#type'
=>
'submit'
,
if
(
in_array
(
$operation
,
[
'enable'
,
'disable'
]))
{
'#value'
=>
t
(
'Save'
),
$operation_active
=
$operation
==
'enable'
;
];
if
(
$rule
->
isActive
()
!=
$operation_active
)
{
$rule
->
setIsActive
(
$operation_active
)
->
save
();
}
$message
=
(
$operation
==
'enable'
)
?
$this
->
t
(
'Messages enabled.'
)
:
$this
->
t
(
'Messages disabled.'
);
}
elseif
(
$operation
==
'delete'
)
{
$rule
->
delete
();
$message
=
$this
->
t
(
'Messages deleted'
);
}
}
return
$form
;
drupal_set_message
(
$message
?
$message
:
$this
->
t
(
'No action performed.'
))
;
}
}
/**
/**
* {@inheritdoc}
* Gets the template collection from an action on the rule.
*
* @param \Drupal\rng\RuleInterface $rule
* The rule.
*
* @return \Drupal\courier\TemplateCollectionInterface|NULL
* A template collection entity, or NULL if no template collection is
* associated.
*/
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
protected
function
getTemplateCollectionForRule
(
RuleInterface
$rule
)
{
$form_rules
=
$form_state
->
getValue
(
'action_list'
);
foreach
(
$rule
->
getActions
()
as
$action
)
{
foreach
(
$this
->
getCommunicationRules
(
$form
[
'#rng_event'
])
as
$rid
=>
$rule
)
{
$conf
=
$action
->
getConfiguration
();
$enabled
=
!
empty
(
$form_rules
[
$rid
][
'status'
]);
$id
=
$conf
[
'template_collection'
];
if
(
$rule
->
isActive
()
!=
$enabled
)
{
if
(
$id
&&
$template_collection
=
TemplateCollection
::
load
(
$id
))
{
$rule
return
$template_collection
;
->
setIsActive
(
$enabled
)
->
save
();
}
}
}
}
return
NULL
;
}
/**
* Gets the condition containing a date instance.
*
* @param \Drupal\rng\RuleInterface $rule
* The rule.
*
* @return \Drupal\rng\RuleComponentInterface|NULL
* A rule component entity, or NULL if no date condition is associated.
*/
protected
function
getDateCondition
(
RuleInterface
$rule
)
{
foreach
(
$rule
->
getConditions
()
as
$component
)
{
$condition
=
$component
->
createInstance
();
if
(
$condition
instanceof
CurrentTime
)
{
return
$component
;
}
}
return
NULL
;
}
/**
* Gets operations for a rule.
*
* @param \Drupal\rng\RuleInterface $rule
* The rule.
*
* @return array
* An array of links suitable for an 'operations' element.
*/
protected
function
getOperations
(
RuleInterface
$rule
)
{
$links
=
[];
$destination
=
$this
->
redirectDestination
->
getAsArray
();
if
(
$component
=
$this
->
getDateCondition
(
$rule
))
{
if
(
$component
->
access
(
'edit'
))
{
$links
[
'edit-date'
]
=
[
'title'
=>
$this
->
t
(
'Edit date'
),
'url'
=>
$component
->
urlInfo
(
'edit-form'
),
'query'
=>
$destination
,
];
}
}
if
(
$rule
->
access
(
'delete'
))
{
$links
[
'delete'
]
=
[
'title'
=>
$this
->
t
(
'Delete'
),
'url'
=>
$rule
->
urlInfo
(
'delete-form'
),
'query'
=>
$destination
,
];
}
drupal_set_message
(
$this
->
t
(
'Messages saved.'
))
;
return
$links
;
}
}
}
}
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