Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
scheduler
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
scheduler
Commits
4b45250a
Commit
4b45250a
authored
3 years ago
by
Jonathan Smith
Committed by
Jonathan Smith
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3224263
by jonathan1055: Inject entityTypeManager to avoid View::load calls
parent
f4f3c984
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Derivative/DynamicLocalTasks.php
+37
-6
37 additions, 6 deletions
src/Plugin/Derivative/DynamicLocalTasks.php
with
37 additions
and
6 deletions
src/Plugin/Derivative/DynamicLocalTasks.php
+
37
−
6
View file @
4b45250a
...
...
@@ -3,8 +3,10 @@
namespace
Drupal\scheduler\Plugin\Derivative
;
use
Drupal\Component\Plugin\Derivative\DeriverBase
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Plugin\Discovery\ContainerDeriverInterface
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\views\Entity\View
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Defines dynamic local tasks.
...
...
@@ -14,18 +16,47 @@ use Drupal\views\Entity\View;
* will not exist and this produces an exception "Route X does not exist." The
* routes are defined here instead to enable checking that the views are loaded.
*/
class
DynamicLocalTasks
extends
DeriverBase
{
class
DynamicLocalTasks
extends
DeriverBase
implements
ContainerDeriverInterface
{
use
StringTranslationTrait
;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
* Creates a DynamicLocalTasks object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public
function
__construct
(
EntityTypeManagerInterface
$entity_type_manager
)
{
$this
->
entityTypeManager
=
$entity_type_manager
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
$base_plugin_id
)
{
return
new
static
(
$container
->
get
(
'entity_type.manager'
)
);
}
/**
* {@inheritdoc}
*/
public
function
getDerivativeDefinitions
(
$base_plugin_definition
)
{
$view_storage
=
$this
->
entityTypeManager
->
getStorage
(
'view'
);
// Define a local task for scheduled content (nodes) view, only when the
// view can be loaded, is enabled and that the overview display exists.
$view
=
View
::
load
(
'scheduler_scheduled_content'
);
/** @var \Drupal\views\ViewEntityInterface $view */
$view
=
$view_storage
->
load
(
'scheduler_scheduled_content'
);
if
(
$view
&&
$view
->
status
()
&&
$view
->
getDisplay
(
'overview'
))
{
// The content overview has weight 0 and moderated content has weight 1
// so use weight 5 for the scheduled content tab.
...
...
@@ -48,7 +79,7 @@ class DynamicLocalTasks extends DeriverBase {
]
+
$base_plugin_definition
;
}
$view
=
V
iew
::
load
(
'scheduler_scheduled_media'
);
$view
=
$v
iew
_storage
->
load
(
'scheduler_scheduled_media'
);
if
(
$view
&&
$view
->
status
()
&&
$view
->
getDisplay
(
'overview'
))
{
// Define local task for scheduled media view.
$this
->
derivatives
[
'scheduler.scheduled_media'
]
=
[
...
...
@@ -67,7 +98,7 @@ class DynamicLocalTasks extends DeriverBase {
]
+
$base_plugin_definition
;
}
$view
=
V
iew
::
load
(
'scheduler_scheduled_commerce_product'
);
$view
=
$v
iew
_storage
->
load
(
'scheduler_scheduled_commerce_product'
);
if
(
$view
&&
$view
->
status
()
&&
$view
->
getDisplay
(
'overview'
))
{
// The page created by route entity.commerce_product.collection does not
// have any tabs or sub-links, because the Commerce Product module does
...
...
@@ -96,7 +127,7 @@ class DynamicLocalTasks extends DeriverBase {
]
+
$base_plugin_definition
;
}
$view
=
V
iew
::
load
(
'scheduler_scheduled_taxonomy_term'
);
$view
=
$v
iew
_storage
->
load
(
'scheduler_scheduled_taxonomy_term'
);
if
(
$view
&&
$view
->
status
()
&&
$view
->
getDisplay
(
'overview'
))
{
// In the same manner as for Commerce Products the page created by route
// entity.taxonomy_vocabulary.collection does not have tabs or sub-links,
...
...
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