Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
layout_builder_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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
layout_builder_reports
Commits
85072e16
Commit
85072e16
authored
Nov 18, 2023
by
r.aubin
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3400856
: Add Drush support
parent
61a3173b
Branches
1.0.x
No related tags found
No related merge requests found
Pipeline
#52180
passed with warnings
Nov 18, 2023
Stage: build
Stage: validate
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
composer.json
+11
-0
11 additions, 0 deletions
composer.json
drush.services.yml
+13
-0
13 additions, 0 deletions
drush.services.yml
src/Commands/LayoutBuilderReportsCommands.php
+149
-0
149 additions, 0 deletions
src/Commands/LayoutBuilderReportsCommands.php
with
173 additions
and
0 deletions
composer.json
0 → 100644
+
11
−
0
View file @
85072e16
{
"name"
:
"drupal/layout_builder_reports"
,
"type"
:
"drupal-module"
,
"extra"
:
{
"drush"
:
{
"services"
:
{
"drush.services.yml"
:
"^10"
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
drush.services.yml
0 → 100644
+
13
−
0
View file @
85072e16
services
:
layout_builder_reports.commands
:
class
:
\Drupal\layout_builder_reports\Commands\LayoutBuilderReportsCommands
tags
:
-
{
name
:
drush.command
}
arguments
:
[
'
@entity_type.manager'
,
'
@entity_display.repository'
,
'
@module_handler'
,
'
@module_installer'
,
'
@extension.list.module'
,
]
This diff is collapsed.
Click to expand it.
src/Commands/LayoutBuilderReportsCommands.php
0 → 100644
+
149
−
0
View file @
85072e16
<?php
namespace
Drupal\layout_builder_reports\Commands
;
use
Drush\Commands\DrushCommands
;
use
Consolidation\AnnotatedCommand\AnnotationData
;
use
Consolidation\AnnotatedCommand\CommandData
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Output\OutputInterface
;
use
Symfony\Component\Console\Input\InputOption
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Entity\EntityDisplayRepositoryInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Extension\ModuleInstallerInterface
;
use
Drupal\Core\Extension\ExtensionList
;
/**
* A Drush commandfile for layout builder reports.
*/
class
LayoutBuilderReportsCommands
extends
DrushCommands
{
protected
$entityTypeManager
;
protected
$entityDisplayRepository
;
protected
$moduleHandler
;
protected
$moduleInstaller
;
protected
$extensionList
;
public
function
__construct
(
EntityTypeManagerInterface
$entityTypeManager
,
EntityDisplayRepositoryInterface
$entityDisplayRepository
,
ModuleHandlerInterface
$moduleHandler
,
ModuleInstallerInterface
$moduleInstaller
,
ExtensionList
$extensionList
)
{
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
entityDisplayRepository
=
$entityDisplayRepository
;
$this
->
moduleHandler
=
$moduleHandler
;
$this
->
moduleInstaller
=
$moduleInstaller
;
$this
->
extensionList
=
$extensionList
;
}
// Dependency injection for services.
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'entity_display.repository'
),
$container
->
get
(
'module_handler'
),
$container
->
get
(
'module_installer'
),
$container
->
get
(
'extension.list.module'
)
);
}
/**
* Outputs a table showing whether Layout Builder is enabled for content types.
*
* @command layout_builder_reports:status
* @aliases lbr-status,lbrs
* @usage layout_builder_reports:status
* Show Layout Builder status for content types.
*/
public
function
status
()
{
$content_types
=
$this
->
entityTypeManager
->
getStorage
(
'node_type'
)
->
loadMultiple
();
$display_modes
=
$this
->
entityDisplayRepository
->
getViewModes
(
'node'
);
// Initialize table.
$table
=
[];
$header
=
[
'Content Type'
,
'Display Mode'
,
'Layout Builder Enabled'
,
'Customizable Layout'
,
];
// Gather data.
foreach
(
$content_types
as
$content_type_id
=>
$content_type
)
{
foreach
(
$display_modes
as
$mode_id
=>
$mode
)
{
$entity_view_display
=
$this
->
entityTypeManager
->
getStorage
(
'entity_view_display'
)
->
load
(
"node.
{
$content_type_id
}
.
{
$mode_id
}
"
);
if
(
$entity_view_display
)
{
$enabled
=
$entity_view_display
->
getThirdPartySetting
(
'layout_builder'
,
'enabled'
,
FALSE
);
$overridable
=
$entity_view_display
->
getThirdPartySetting
(
'layout_builder'
,
'allow_custom'
,
FALSE
);
// Add row to table.
$table
[]
=
[
'Content Type'
=>
$content_type
->
label
(),
'Display Mode'
=>
$mode
[
'label'
],
'Layout Builder Enabled'
=>
$enabled
?
'<info>Yes</info>'
:
'No'
,
'Customizable Layout'
=>
$enabled
&&
$overridable
?
'Yes'
:
'No'
,
];
}
}
}
// Render the table.
if
(
!
empty
(
$table
))
{
$this
->
io
()
->
table
(
$header
,
$table
);
}
else
{
$this
->
io
()
->
warning
(
"No content types found or no view modes with Layout Builder enabled."
);
}
}
/**
* Outputs a table of all modules that require Layout Builder.
*
* @command layout_builder_reports:dependency-modules
* @aliases lbrdeps
* @option installed Show only installed modules.
* @option uninstalled Show only uninstalled modules.
* @usage layout_builder_reports:dependency-modules
* Show modules that have Layout Builder as a dependency.
* @usage layout_builder_reports:dependency-modules --installed
* Show only installed modules that have Layout Builder as a dependency.
* @usage layout_builder_reports:dependency-modules --uninstalled
* Show only uninstalled modules that have Layout Builder as a dependency.
*/
public
function
dependencyModules
(
$options
=
[
'installed'
=>
FALSE
,
'uninstalled'
=>
FALSE
])
{
$modules_with_dependency
=
[];
$all_modules
=
$this
->
extensionList
->
getList
();
foreach
(
$all_modules
as
$module
)
{
$info
=
$module
->
info
;
if
(
isset
(
$info
[
'dependencies'
])
&&
in_array
(
'drupal:layout_builder'
,
$info
[
'dependencies'
]))
{
$is_installed
=
$this
->
moduleHandler
->
moduleExists
(
$module
->
getName
());
if
((
$options
[
'installed'
]
&&
!
$is_installed
)
||
(
$options
[
'uninstalled'
]
&&
$is_installed
))
{
continue
;
}
$modules_with_dependency
[]
=
[
'Module Name'
=>
$info
[
'name'
]
??
$module
->
getName
(),
'Module Machine Name'
=>
$module
->
getName
(),
'Installed'
=>
$is_installed
?
'Yes'
:
'No'
,
];
}
}
if
(
!
empty
(
$modules_with_dependency
))
{
$header
=
[
'Module Name'
,
'Module Machine Name'
,
'Installed'
];
$this
->
io
()
->
table
(
$header
,
$modules_with_dependency
);
}
else
{
$this
->
io
()
->
success
(
"No modules matching the criteria have Layout Builder as a dependency."
);
}
}
}
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