Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rng-3202298
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
rng-3202298
Commits
1c86bd93
Commit
1c86bd93
authored
8 years ago
by
dpi
Browse files
Options
Downloads
Patches
Plain Diff
Added ability to delete all custom rules for an event type.
Fixed
#72
parent
764fb436
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rng.routing.yml
+13
-1
13 additions, 1 deletion
rng.routing.yml
src/Form/EventTypeAccessDefaultsForm.php
+18
-1
18 additions, 1 deletion
src/Form/EventTypeAccessDefaultsForm.php
src/Form/EventTypeRuleDeleteAll.php
+141
-0
141 additions, 0 deletions
src/Form/EventTypeRuleDeleteAll.php
with
172 additions
and
2 deletions
rng.routing.yml
+
13
−
1
View file @
1c86bd93
...
...
@@ -151,6 +151,18 @@ entity.event_type.access_defaults:
requirements
:
_permission
:
'
administer
event
types'
entity.event_type.access_defaults.delete_all
:
path
:
'
/admin/structure/rng/event_types/manage/{event_type}/access_defaults/delete'
defaults
:
_form
:
'
\Drupal\rng\Form\EventTypeRuleDeleteAll'
_title
:
'
Delete
all
event
custom
rules'
requirements
:
_permission
:
'
administer
event
types'
options
:
parameters
:
rng_event_type_rule
:
type
:
'
entity:rng_event_type_rule'
rng.event_type.overview
:
path
:
'
/admin/structure/rng/event_types'
defaults
:
...
...
@@ -161,7 +173,7 @@ rng.event_type.overview:
_permission
:
'
administer
event
types'
# Event type rules
rng.rng_event_type_rule
:
rng.rng_event_type_rule
.component.edit
:
path
:
'
/admin/structure/rng/event_type_rule/{rng_event_type_rule}/{component_type}/{component_id}/edit'
defaults
:
_form
:
'
\Drupal\rng\Form\EventTypeRuleComponentEdit'
...
...
This diff is collapsed.
Click to expand it.
src/Form/EventTypeAccessDefaultsForm.php
+
18
−
1
View file @
1c86bd93
...
...
@@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use
Drupal\rng\EventManagerInterface
;
use
Drupal\rng\RNGConditionInterface
;
use
Drupal\Core\Cache\Cache
;
use
Drupal\Core\Url
;
/**
* Form for event type access defaults.
...
...
@@ -201,7 +202,7 @@ class EventTypeAccessDefaultsForm extends EntityForm {
'#type'
=>
'operations'
,
'#links'
=>
[
'edit'
=>
[
'title'
=>
t
(
'Edit'
),
'url'
=>
\Drupal\Core\
Url
::
fromRoute
(
'rng.rng_event_type_rule'
,
[
'url'
=>
Url
::
fromRoute
(
'rng.rng_event_type_rule
.component.edit
'
,
[
'rng_event_type_rule'
=>
$rule
->
id
(),
'component_type'
=>
'condition'
,
'component_id'
=>
$id
,
...
...
@@ -321,8 +322,24 @@ class EventTypeAccessDefaultsForm extends EntityForm {
* Remove delete element since it is confusing on non CRUD forms.
*/
protected
function
actions
(
array
$form
,
FormStateInterface
$form_state
)
{
/** @var \Drupal\rng\EventTypeInterface $event_type */
$event_type
=
$this
->
entity
;
$actions
=
parent
::
actions
(
$form
,
$form_state
);
unset
(
$actions
[
'delete'
]);
$actions
[
'delete-custom-rules'
]
=
array
(
'#type'
=>
'link'
,
'#title'
=>
$this
->
t
(
'Delete all custom rules'
),
'#attributes'
=>
array
(
'class'
=>
array
(
'button'
,
'button--danger'
),
),
);
$actions
[
'delete-custom-rules'
][
'#url'
]
=
Url
::
fromRoute
(
'entity.event_type.access_defaults.delete_all'
,
[
'event_type'
=>
$event_type
->
id
(),
]);
return
$actions
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Form/EventTypeRuleDeleteAll.php
0 → 100644
+
141
−
0
View file @
1c86bd93
<?php
/**
* @file
* Contains \Drupal\rng\Form\EventTypeRuleDeleteAll.
*/
namespace
Drupal\rng\Form
;
use
Drupal\Core\Form\ConfirmFormBase
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\rng\EventManagerInterface
;
use
Drupal\rng\EventTypeInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Url
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Cache\Cache
;
/**
* Form controller to delete all custom rules for an event type.
*/
class
EventTypeRuleDeleteAll
extends
ConfirmFormBase
{
/**
* The event type entity.
*
* @var \Drupal\rng\EventTypeInterface
*/
protected
$eventType
;
/**
* Rule storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected
$ruleStorage
;
/**
* The RNG event manager.
*
* @var \Drupal\rng\EventManagerInterface
*/
protected
$eventManager
;
/**
* Constructs a EventTypeRuleDeleteAll form.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\rng\EventManagerInterface $event_manager
* The RNG event manager.
*/
public
function
__construct
(
EntityTypeManagerInterface
$entity_type_manager
,
EventManagerInterface
$event_manager
)
{
$this
->
ruleStorage
=
$entity_type_manager
->
getStorage
(
'rng_rule'
);
$this
->
eventManager
=
$event_manager
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'rng.event_manager'
)
);
}
/**
* {@inheritdoc}
*/
public
function
getFormId
()
{
return
'rng_event_type_rule_delete_all'
;
}
/**
* {@inheritdoc}
*/
public
function
getQuestion
()
{
return
$this
->
t
(
'Are you sure you want to delete custom access rules for all events?'
);
}
/**
* {@inheritdoc}
*/
public
function
getDescription
()
{
return
$this
->
t
(
'All custom rules for events will be deleted. All events will use event type defaults.'
);
}
/**
* {@inheritdoc}
*/
public
function
getConfirmText
()
{
return
$this
->
t
(
'Delete all existing access rules'
);
}
/**
* {@inheritdoc}
*/
public
function
getCancelUrl
()
{
return
Url
::
fromRoute
(
'entity.event_type.access_defaults'
,
[
'event_type'
=>
$this
->
eventType
->
id
(),
]);
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
,
EventTypeInterface
$event_type
=
NULL
)
{
$this
->
eventType
=
$event_type
;
return
parent
::
buildForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
/** @var \Drupal\rng\RuleInterface[] $rules */
$rules
=
$this
->
ruleStorage
->
loadByProperties
([
'event__target_type'
=>
$this
->
eventType
->
getEventEntityTypeId
(),
]);
// There is no bundle field on rules. Load all rules one-by-one and find
// the bundle for each event.
$count
=
0
;
foreach
(
$rules
as
$rule
)
{
$event
=
$rule
->
getEvent
();
// If event no longer exists then delete the rules while we're here.
if
(
!
$event
||
$event
->
bundle
()
==
$this
->
eventType
->
getEventBundle
())
{
$rule
->
delete
();
$count
++
;
}
}
drupal_set_message
(
$this
->
formatPlural
(
$count
,
'@count custom access rule deleted.'
,
'@count custom access rules deleted.'
));
$this
->
eventManager
->
invalidateEventType
(
$this
->
eventType
);
$form_state
->
setRedirectUrl
(
$this
->
getCancelUrl
());
}
}
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