Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aggrid
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
aggrid
Commits
c6cdbecc
Commit
c6cdbecc
authored
4 years ago
by
Mike Feranda
Committed by
Mike Feranda
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3161356
by mferanda: Suppression - Add ability to automatically suppress other cells
parent
d1900d2a
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
aggrid.schema.yml
+7
-0
7 additions, 0 deletions
aggrid.schema.yml
src/Plugin/Field/FieldFormatter/HtmlFormatterType.php
+112
-24
112 additions, 24 deletions
src/Plugin/Field/FieldFormatter/HtmlFormatterType.php
with
119 additions
and
24 deletions
aggrid.schema.yml
+
7
−
0
View file @
c6cdbecc
field.formatter.settings.html_formatter_type
:
type
:
mapping
label
:
'
HTML
Formatter
Suppression
override'
mapping
:
suppression_override
:
type
:
boolean
label
:
'
Suppression
override'
This diff is collapsed.
Click to expand it.
src/Plugin/Field/FieldFormatter/HtmlFormatterType.php
+
112
−
24
View file @
c6cdbecc
...
@@ -11,7 +11,7 @@ use Drupal\Core\Field\FormatterBase;
...
@@ -11,7 +11,7 @@ use Drupal\Core\Field\FormatterBase;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\FormStateInterface
;
/**
/**
* Plugin implementation of the '
aggrid
_formatter_type' formatter.
* Plugin implementation of the '
html
_formatter_type' formatter.
*
*
* @FieldFormatter(
* @FieldFormatter(
* id = "html_formatter_type",
* id = "html_formatter_type",
...
@@ -28,6 +28,7 @@ class HtmlFormatterType extends FormatterBase {
...
@@ -28,6 +28,7 @@ class HtmlFormatterType extends FormatterBase {
*/
*/
public
static
function
defaultSettings
()
{
public
static
function
defaultSettings
()
{
return
[
return
[
'suppression_override'
=>
false
,
// Implement default settings.
// Implement default settings.
]
+
parent
::
defaultSettings
();
]
+
parent
::
defaultSettings
();
}
}
...
@@ -36,9 +37,18 @@ class HtmlFormatterType extends FormatterBase {
...
@@ -36,9 +37,18 @@ class HtmlFormatterType extends FormatterBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
settingsForm
(
array
$form
,
FormStateInterface
$form_state
)
{
public
function
settingsForm
(
array
$form
,
FormStateInterface
$form_state
)
{
return
[
// Implement settings form.
$form
=
parent
::
settingsForm
(
$form
,
$form_state
);
]
+
parent
::
settingsForm
(
$form
,
$form_state
);
$form
[
'suppression_override'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Suppression override'
),
'#description'
=>
$this
->
t
(
'If enabled, suppression will be ignored'
),
'#default_value'
=>
$this
->
getSetting
(
'suppression_override'
),
];
return
$form
;
}
}
/**
/**
...
@@ -47,6 +57,9 @@ class HtmlFormatterType extends FormatterBase {
...
@@ -47,6 +57,9 @@ class HtmlFormatterType extends FormatterBase {
public
function
settingsSummary
()
{
public
function
settingsSummary
()
{
$summary
=
[];
$summary
=
[];
// Implement settings summary.
// Implement settings summary.
if
(
$override
=
$this
->
getSetting
(
'suppression_override'
)
?
'Yes'
:
'No'
)
{
$summary
[]
=
$this
->
t
(
'Suppression override: @suppover'
,
[
'@suppover'
=>
$override
]);
}
return
$summary
;
return
$summary
;
}
}
...
@@ -74,16 +87,107 @@ class HtmlFormatterType extends FormatterBase {
...
@@ -74,16 +87,107 @@ class HtmlFormatterType extends FormatterBase {
return
$rowSettings
;
return
$rowSettings
;
}
}
/**
* @param $rowSettings
* @param $headers
* @param $rowData
* @return mixed
*/
public
function
processSuppression
(
$rowSettings
,
$headers
,
$rowData
)
{
$current_user
=
\Drupal
::
currentUser
();
$roles
=
$current_user
->
getRoles
();
$settings
=
$this
->
getSettings
();
// Get suppression override setting
if
(
!
empty
(
$settings
[
'suppression_override'
]))
{
$suppOverride
=
$settings
[
'suppression_override'
];
}
/*
* Basic level 1 suppression
*
* This will review the items and check settings for anything marked as
* suppressed. Those cells will be immediately suppressed.
*
* Level 1 includes items that are marked for other suppression.
*
*/
// Suppression variables
$suppCell
=
[];
$suppCount
=
[];
if
(
is_array
(
$rowData
))
{
for
(
$i
=
0
;
$i
<
count
(
$rowData
);
$i
++
)
{
// Each row... then each cell in each row.
foreach
(
$headers
as
$field
)
{
// Check if suppression is enabled for cell or if the cell is already marked for suppression
$suppCellProcess
=
(
isset
(
$rowData
[
$i
]
->
$field
)
&&
is_numeric
(
$rowData
[
$i
]
->
$field
)
&&
((
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'min'
])
&&
$rowData
[
$i
]
->
$field
>=
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'min'
]
&&
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'max'
])
&&
$rowData
[
$i
]
->
$field
<=
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'max'
]
||
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'any'
])
&&
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'any'
]))
&&
(
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'role'
])
&&
!
empty
(
array_intersect
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'role'
],
$roles
))
||
!
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'role'
]))
||
in_array
(
$suppCell
[
$i
],
$field
));
// Check if suppression and for role. If suppressed, add it to suppression list.
if
(
$suppCellProcess
)
{
// Add the current cell to the suppression
if
(
!
in_array
(
$suppCell
[
$i
],
$field
))
{
array_push
(
$suppCell
,
[
$i
=>
$field
]);
}
// Additional Suppression
if
(
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'otherRowCol'
]))
{
// Set the other Row/Col from setting
$otherRowCol
=
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'otherRowCol'
];
// Loop through other Row/Column and set
foreach
(
$otherRowCol
as
$otherRow
=>
$value
)
{
foreach
(
$value
as
$key
=>
$otherField
)
{
if
(
!
in_array
(
$suppCell
[
$otherRow
],
$otherField
))
{
array_push
(
$suppCell
,
[
$otherRow
=>
$otherField
]);
}
}
}
}
}
}
}
}
// Process actual suppressions
if
(
!
$suppOverride
)
{
foreach
(
$suppCell
as
$key
=>
$value
)
{
foreach
(
$value
as
$row
=>
$field
)
{
$rowData
[
$row
]
->
$field
=
'+'
;
}
}
}
return
$rowData
;
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
createAggridRowData
(
$rowSettings
,
$headers
,
$rowData
)
{
public
function
createAggridRowData
(
$rowSettings
,
$headers
,
$rowData
)
{
// Get user.
// Get user.
$current_user
=
\Drupal
::
currentUser
();
$current_user
=
\Drupal
::
currentUser
();
$roles
=
$current_user
->
getRoles
();
$roles
=
$current_user
->
getRoles
();
// Cycle through suppression multiple times
if
(
is_array
(
$rowData
))
{
for
(
$i
=
0
;
$i
<
4
;
$i
++
)
{
$rowData
=
$this
->
processSuppression
(
$rowSettings
,
$headers
,
$rowData
);
}
}
// HTML rendering
$table_render
=
''
;
$table_render
=
''
;
$spanSkip
[][]
=
0
;
$spanSkip
[][]
=
0
;
if
(
is_array
(
$rowData
))
{
if
(
is_array
(
$rowData
))
{
...
@@ -148,25 +252,9 @@ class HtmlFormatterType extends FormatterBase {
...
@@ -148,25 +252,9 @@ class HtmlFormatterType extends FormatterBase {
}
else
{
}
else
{
$cellScope
=
''
;
$cellScope
=
''
;
}
}
// Check if suppression and for role. If suppressed, send a '+' as value.
if
(
isset
(
$rowData
[
$i
]
->
$field
)
&&
is_numeric
(
$rowData
[
$i
]
->
$field
)
&&
((
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'min'
])
&&
$rowData
[
$i
]
->
$field
>=
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'min'
]
&&
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'max'
])
&&
$rowData
[
$i
]
->
$field
<=
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'max'
]
||
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'any'
])
&&
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'any'
])
&&
isset
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'role'
])
&&
!
empty
(
array_intersect
(
$rowSettings
[
$i
][
$field
][
'valueSuppression'
][
'role'
],
$roles
)))
)
{
$fieldValue
=
'+'
;
}
elseif
(
isset
(
$rowData
[
$i
]
->
$field
))
{
// Check if there is data.
$fieldValue
=
$rowData
[
$i
]
->
$field
;
}
else
{
// If not, send blank variable.
$fieldValue
=
''
;
}
// Finally, display the cell.
// Finally, display the cell.
$table_render
.
=
'<td '
.
$cellScope
.
' rowspan="'
.
$rowSpan
.
'" colspan="'
.
$colSpan
.
'" class="'
.
$cellClass
.
'">'
.
$field
Value
.
'</td>'
;
$table_render
.
=
'<td '
.
$cellScope
.
' rowspan="'
.
$rowSpan
.
'" colspan="'
.
$colSpan
.
'" class="'
.
$cellClass
.
'">'
.
$
rowData
[
$i
]
->
$
field
.
'</td>'
;
}
elseif
(
$spanSkip
[
$i
][
$colCount
]
>
0
)
{
}
elseif
(
$spanSkip
[
$i
][
$colCount
]
>
0
)
{
// No need to render the cell.
// No need to render the cell.
}
else
{
}
else
{
...
@@ -188,7 +276,7 @@ class HtmlFormatterType extends FormatterBase {
...
@@ -188,7 +276,7 @@ class HtmlFormatterType extends FormatterBase {
$elements
=
[];
$elements
=
[];
$aggridDefault
=
[];
$aggridDefault
=
[];
$gsRowSettingsDefault
=
[];
$gsRowSettingsDefault
=
[];
// Get config for aggrid.
// Get config for aggrid.
$config
=
\Drupal
::
config
(
'aggrid.general'
);
$config
=
\Drupal
::
config
(
'aggrid.general'
);
...
...
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