Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uswds_ckeditor_integration
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
uswds_ckeditor_integration
Commits
4e93392f
Commit
4e93392f
authored
3 months ago
by
Stephen Mustgrave
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3481732
by edwardsay: Stacked table without header causes warnings
parent
dd5d85e3
Branches
1.0.x
Tags
1.0.1
1 merge request
!87
Issue #3481732 by edwardsay: Stacked table without header causes warnings
Pipeline
#314802
passed with warnings
3 months ago
Stage: build
Stage: validate
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Filter/FilterUswdsTableStacked.php
+90
-0
90 additions, 0 deletions
src/Plugin/Filter/FilterUswdsTableStacked.php
with
90 additions
and
0 deletions
src/Plugin/Filter/Filter
TableAttributes
.php
→
src/Plugin/Filter/Filter
UswdsTableStacked
.php
+
90
−
0
View file @
4e93392f
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\uswds_ckeditor_integration\Plugin\Filter
;
use
Drupal\Component\Utility\Html
;
use
Drupal\Core\Logger\LoggerChannelTrait
;
use
Drupal\filter\FilterProcessResult
;
use
Drupal\filter\Plugin\FilterBase
;
...
...
@@ -16,7 +17,9 @@
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
* )
*/
class
FilterTableAttributes
extends
FilterBase
{
class
FilterUswdsTableStacked
extends
FilterBase
{
use
LoggerChannelTrait
;
/**
* {@inheritdoc}
...
...
@@ -31,45 +34,48 @@ public function process($text, $langcode): FilterProcessResult {
// Add USWDS Class to table.
foreach
(
$tables
as
$table
)
{
$rows
=
$xpath
->
query
(
'.//tr'
,
$table
);
$headers
=
$xpath
->
query
(
'//thead//th'
,
$rows
->
item
(
0
));
$table_headers
=
[];
// Add attributes to column headers.
foreach
(
$headers
as
$header
)
{
$header
->
setAttribute
(
'scope'
,
'col'
);
$label
=
$header
->
nodeValue
;
$table_headers
[]
=
$label
;
}
$headers
=
$xpath
->
query
(
'.//thead//th'
,
$rows
->
item
(
0
));
// Add scope to row.
$skip_first
=
TRUE
;
foreach
(
$rows
as
$row
)
{
if
(
$skip_first
)
{
$skip_first
=
FALSE
;
continue
;
if
(
$headers
->
length
>
0
)
{
$table_headers
=
[];
// Add attributes to column headers.
foreach
(
$headers
as
$header
)
{
$header
->
setAttribute
(
'scope'
,
'col'
);
$label
=
$header
->
nodeValue
;
$table_headers
[]
=
$label
;
}
$counter
=
0
;
foreach
(
$row
->
childNodes
as
$key
=>
$tag
)
{
switch
(
$tag
->
nodeName
)
{
case
'td'
:
$data_label
=
$table_headers
[
$counter
];
$tag
->
setAttribute
(
'data-label'
,
$data_label
);
if
(
$key
===
0
)
{
$tag
->
setAttribute
(
'scope'
,
'row'
);
}
$counter
++
;
break
;
default
:
break
;
// Add scope to row.
$skip_first
=
TRUE
;
foreach
(
$rows
as
$row
)
{
if
(
$skip_first
)
{
$skip_first
=
FALSE
;
continue
;
}
$counter
=
0
;
foreach
(
$row
->
childNodes
as
$key
=>
$tag
)
{
switch
(
$tag
->
nodeName
)
{
case
'td'
:
$data_label
=
$table_headers
[
$counter
];
$tag
->
setAttribute
(
'data-label'
,
$data_label
);
if
(
$key
===
0
)
{
$tag
->
setAttribute
(
'scope'
,
'row'
);
}
$counter
++
;
break
;
default
:
break
;
}
}
}
$result
->
setProcessedText
(
Html
::
serialize
(
$dom
));
}
else
{
$this
->
getLogger
(
'uswds_ckeditor_integration'
)
->
warning
(
'Table without header trying to use USWDS stacked, not setting header is an accessibility issue.'
);
}
}
$result
->
setProcessedText
(
Html
::
serialize
(
$dom
));
}
return
$result
;
}
...
...
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