Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
layout_builder_usage_reports
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
layout_builder_usage_reports
Commits
656bf989
Commit
656bf989
authored
1 year ago
by
Sidharth Soman
Committed by
Michael Caldwell
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3373117
by sidharth_soman, justcaldwell: Fix the errors reported by phpcs
parent
4ac1e3dc
No related branches found
No related tags found
1 merge request
!11
Fixed phpcs issues.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Form/ReportForm.php
+77
-23
77 additions, 23 deletions
src/Form/ReportForm.php
with
77 additions
and
23 deletions
src/Form/ReportForm.php
+
77
−
23
View file @
656bf989
...
@@ -2,15 +2,32 @@
...
@@ -2,15 +2,32 @@
namespace
Drupal\layout_builder_usage_reports\Form
;
namespace
Drupal\layout_builder_usage_reports\Form
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Link
;
use
Drupal\Core\Link
;
use
Drupal\Core\State\StateInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
/**
* C
lass R
eport
F
orm.
* C
onstructs the r
eport
f
orm.
*/
*/
class
ReportForm
extends
FormBase
{
class
ReportForm
extends
FormBase
{
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected
$state
;
/**
* The database service.
*
* @var \Drupal\Core\Database\Connection
*/
protected
$database
;
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
...
@@ -18,6 +35,35 @@ class ReportForm extends FormBase {
...
@@ -18,6 +35,35 @@ class ReportForm extends FormBase {
return
'report_form'
;
return
'report_form'
;
}
}
/**
* Constructs a new ReportForm object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Core\Database\Connection $database
* The database service.
*/
public
function
__construct
(
StateInterface
$state
,
Connection
$database
)
{
$this
->
state
=
$state
;
$this
->
database
=
$database
;
}
/**
* Implements the create() method for the form.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The Drupal service container.
*
* @return static
* The instance of the form.
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'state'
),
$container
->
get
(
'database'
)
);
}
/**
/**
* Return true if a string starts with the specified character/ string.
* Return true if a string starts with the specified character/ string.
*/
*/
...
@@ -30,11 +76,11 @@ class ReportForm extends FormBase {
...
@@ -30,11 +76,11 @@ class ReportForm extends FormBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$lbur_bundle
=
\Drupal
::
state
()
->
get
(
'lbur_bundle'
);
$lbur_bundle
=
$this
->
state
->
get
(
'lbur_bundle'
);
$lbur_provider
=
\Drupal
::
state
()
->
get
(
'lbur_provider'
);
$lbur_provider
=
$this
->
state
->
get
(
'lbur_provider'
);
$lbur_language
=
\Drupal
::
state
()
->
get
(
'lbur_language'
);
$lbur_language
=
$this
->
state
->
get
(
'lbur_language'
);
$lbur_block_type
=
\Drupal
::
state
()
->
get
(
'lbur_block_type'
);
$lbur_block_type
=
$this
->
state
->
get
(
'lbur_block_type'
);
$lbur_paragraph_type
=
\Drupal
::
state
()
->
get
(
'lbur_paragraph_type'
);
$lbur_paragraph_type
=
$this
->
state
->
get
(
'lbur_paragraph_type'
);
$header
=
[
$header
=
[
'entity_id'
=>
$this
->
t
(
'Node ID'
),
'entity_id'
=>
$this
->
t
(
'Node ID'
),
...
@@ -45,7 +91,7 @@ class ReportForm extends FormBase {
...
@@ -45,7 +91,7 @@ class ReportForm extends FormBase {
'label'
=>
$this
->
t
(
'Label'
),
'label'
=>
$this
->
t
(
'Label'
),
'provider'
=>
$this
->
t
(
'Provider'
),
'provider'
=>
$this
->
t
(
'Provider'
),
];
];
$database
=
\Drupal
::
database
()
;
$database
=
$this
->
database
;
$result
=
[];
$result
=
[];
$options
=
[];
$options
=
[];
$display_reset
=
TRUE
;
$display_reset
=
TRUE
;
...
@@ -87,10 +133,17 @@ class ReportForm extends FormBase {
...
@@ -87,10 +133,17 @@ class ReportForm extends FormBase {
continue
;
continue
;
}
}
$serialized_data
=
$record
->
layout_builder__layout_section
;
$serialized_data
=
$record
->
layout_builder__layout_section
;
$unserialized_data
=
unserialize
(
$serialized_data
);
$unserialized_data
=
unserialize
(
$serialized_data
,
[
'allowed_classes'
=>
[
'Drupal\layout_builder\Section'
,
'Drupal\layout_builder\SectionComponent'
,
],
]
);
$components
=
$unserialized_data
->
getComponents
();
$components
=
$unserialized_data
->
getComponents
();
foreach
(
$components
as
$components_id
=>
$component
)
{
foreach
(
$components
as
$component
)
{
$pluginId
=
$component
->
getPluginId
();
$pluginId
=
$component
->
getPluginId
();
/*
/*
* inline_block:title_and_supporting_message
* inline_block:title_and_supporting_message
...
@@ -105,14 +158,14 @@ class ReportForm extends FormBase {
...
@@ -105,14 +158,14 @@ class ReportForm extends FormBase {
$paragraph_type
=
''
;
$paragraph_type
=
''
;
if
(
$this
->
startsWith
(
$pluginId
,
"inline_block:"
))
{
if
(
$this
->
startsWith
(
$pluginId
,
"inline_block:"
))
{
// It's block type.
// It's block type.
$block_type
=
(
isset
(
$pluginIdPartsArray
[
1
]
)
?
$pluginIdPartsArray
[
1
]
:
''
);
$block_type
=
(
$pluginIdPartsArray
[
1
]
?
?
''
);
if
(
!
empty
(
$block_type
))
{
if
(
!
empty
(
$block_type
))
{
$block_types_set
[
$block_type
]
=
$block_type
;
$block_types_set
[
$block_type
]
=
$block_type
;
}
}
}
}
elseif
(
$this
->
startsWith
(
$pluginId
,
"component:"
))
{
elseif
(
$this
->
startsWith
(
$pluginId
,
"component:"
))
{
// It's paragraph type.
// It's paragraph type.
$paragraph_type
=
(
isset
(
$pluginIdPartsArray
[
1
]
)
?
$pluginIdPartsArray
[
1
]
:
''
);
$paragraph_type
=
(
$pluginIdPartsArray
[
1
]
?
?
''
);
if
(
!
empty
(
$paragraph_type
))
{
if
(
!
empty
(
$paragraph_type
))
{
$paragraph_types_set
[
$paragraph_type
]
=
$paragraph_type
;
$paragraph_types_set
[
$paragraph_type
]
=
$paragraph_type
;
}
}
...
@@ -201,7 +254,7 @@ class ReportForm extends FormBase {
...
@@ -201,7 +254,7 @@ class ReportForm extends FormBase {
if
(
$display_reset
)
{
if
(
$display_reset
)
{
$form
[
'filtergroup'
][
'reset'
]
=
[
$form
[
'filtergroup'
][
'reset'
]
=
[
'#type'
=>
'submit'
,
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Reset the filter'
),
'#value'
=>
$this
->
t
(
'Reset the filter'
),
'#submit'
=>
[[
$this
,
'resetForm'
]],
'#submit'
=>
[[
$this
,
'resetForm'
]],
];
];
}
}
...
@@ -230,7 +283,7 @@ class ReportForm extends FormBase {
...
@@ -230,7 +283,7 @@ class ReportForm extends FormBase {
*/
*/
public
function
validateForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
public
function
validateForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
foreach
(
$form_state
->
getValues
()
as
$key
=>
$value
)
{
foreach
(
$form_state
->
getValues
()
as
$key
=>
$value
)
{
// @
TODO:
Validate fields.
// @
todo
Validate fields.
}
}
parent
::
validateForm
(
$form
,
$form_state
);
parent
::
validateForm
(
$form
,
$form_state
);
}
}
...
@@ -239,21 +292,22 @@ class ReportForm extends FormBase {
...
@@ -239,21 +292,22 @@ class ReportForm extends FormBase {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
\Drupal
::
state
()
->
set
(
'lbur_bundle'
,
$form_state
->
getValues
()[
"bundle"
]);
$this
->
state
->
set
(
'lbur_bundle'
,
$form_state
->
getValues
()[
"bundle"
]);
\Drupal
::
state
()
->
set
(
'lbur_provider'
,
$form_state
->
getValues
()[
"provider"
]);
$this
->
state
->
set
(
'lbur_provider'
,
$form_state
->
getValues
()[
"provider"
]);
\Drupal
::
state
()
->
set
(
'lbur_language'
,
$form_state
->
getValues
()[
"language"
]);
$this
->
state
->
set
(
'lbur_language'
,
$form_state
->
getValues
()[
"language"
]);
\Drupal
::
state
()
->
set
(
'lbur_block_type'
,
$form_state
->
getValues
()[
"block_type"
]);
$this
->
state
->
set
(
'lbur_block_type'
,
$form_state
->
getValues
()[
"block_type"
]);
\Drupal
::
state
()
->
set
(
'lbur_paragraph_type'
,
$form_state
->
getValues
()[
"paragraph_type"
]);
$this
->
state
->
set
(
'lbur_paragraph_type'
,
$form_state
->
getValues
()[
"paragraph_type"
]);
}
}
/**
/**
* Reset the filter.
* Reset the filter.
*/
*/
public
function
resetForm
()
{
public
function
resetForm
()
{
\Drupal
::
state
()
->
delete
(
'lbur_bundle'
);
$this
->
state
->
delete
(
'lbur_bundle'
);
\Drupal
::
state
()
->
delete
(
'lbur_provider'
);
$this
->
state
->
delete
(
'lbur_provider'
);
\Drupal
::
state
()
->
delete
(
'lbur_language'
);
$this
->
state
->
delete
(
'lbur_language'
);
\Drupal
::
state
()
->
delete
(
'lbur_block_type'
);
$this
->
state
->
delete
(
'lbur_block_type'
);
\Drupal
::
state
()
->
delete
(
'lbur_paragraph_type'
);
$this
->
state
->
delete
(
'lbur_paragraph_type'
);
}
}
}
}
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