Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
simple_sitemap
Commits
c8085d85
Commit
c8085d85
authored
Mar 11, 2016
by
Sam152
Committed by
Pawel G
Mar 11, 2016
Browse files
Issue
#2684781
by Sam152: Inject the database service into LinkGeneratorBase
parent
c05868fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/LinkGeneratorBase.php
View file @
c8085d85
<?php
/**
* @file
* Contains \Drupal\simple_sitemap\LinkGeneratorBase.
...
...
@@ -7,7 +8,44 @@
namespace
Drupal\simple_sitemap
;
use
Drupal\Component\Plugin\PluginBase
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* A link generator plugin base.
*/
abstract
class
LinkGeneratorBase
extends
PluginBase
implements
LinkGeneratorInterface
,
ContainerFactoryPluginInterface
{
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected
$database
;
/**
* LinkGeneratorBase constructor.
*
* @param array $configuration
* The plugin configuration
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
Connection
$database
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
database
=
$database
;
}
abstract
class
LinkGeneratorBase
extends
PluginBase
implements
LinkGeneratorInterface
{
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'database'
));
}
}
src/Plugin/LinkGenerator/Menu.php
View file @
c8085d85
...
...
@@ -39,7 +39,7 @@ class Menu extends LinkGeneratorBase {
* {@inheritdoc}
*/
public
function
getQuery
(
$bundle
)
{
return
\
Drupal
::
database
()
->
select
(
'menu_tree'
,
'm'
)
return
$this
->
database
->
select
(
'menu_tree'
,
'm'
)
->
fields
(
'm'
,
array
(
'mlid'
,
'route_name'
,
'route_parameters'
,
'options'
))
->
condition
(
'menu_name'
,
$bundle
)
->
condition
(
'enabled'
,
1
)
...
...
src/Plugin/LinkGenerator/NodeType.php
View file @
c8085d85
...
...
@@ -40,7 +40,7 @@ class NodeType extends LinkGeneratorBase {
* {@inheritdoc}
*/
public
function
getQuery
(
$bundle
)
{
return
\
Drupal
::
database
()
->
select
(
'node_field_data'
,
'n'
)
return
$this
->
database
->
select
(
'node_field_data'
,
'n'
)
->
fields
(
'n'
,
array
(
'nid'
,
'changed'
))
->
condition
(
'type'
,
$bundle
)
->
condition
(
'status'
,
1
);
...
...
src/Plugin/LinkGenerator/TaxonomyVocabulary.php
View file @
c8085d85
...
...
@@ -40,7 +40,7 @@ class TaxonomyVocabulary extends LinkGeneratorBase {
* {@inheritdoc}
*/
public
function
getQuery
(
$bundle
)
{
return
\
Drupal
::
database
()
->
select
(
'taxonomy_term_field_data'
,
't'
)
return
$this
->
database
->
select
(
'taxonomy_term_field_data'
,
't'
)
->
fields
(
't'
,
array
(
'tid'
,
'changed'
))
->
condition
(
'vid'
,
$bundle
);
}
...
...
src/Plugin/LinkGenerator/User.php
View file @
c8085d85
...
...
@@ -41,7 +41,7 @@ class User extends LinkGeneratorBase {
* {@inheritdoc}
*/
public
function
getQuery
(
$bundle
)
{
return
\
Drupal
::
database
()
->
select
(
'users_field_data'
,
'u'
)
return
$this
->
database
->
select
(
'users_field_data'
,
'u'
)
->
fields
(
'u'
,
array
(
'uid'
,
'changed'
))
->
condition
(
'status'
,
1
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment