Commit c8085d85 authored by Sam152's avatar Sam152 Committed by gbyte.co

Issue #2684781 by Sam152: Inject the database service into LinkGeneratorBase

parent c05868fc
<?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'));
}
}
......@@ -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)
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment