Commit 2e83a6c5 authored by Sam152's avatar Sam152 Committed by gbyte.co

Issue #2684771 by Sam152: Update LinkGeneratorInterface to enforce what link...

Issue #2684771 by Sam152: Update LinkGeneratorInterface to enforce what link generators need to provide
parent 62a9446d
......@@ -14,4 +14,23 @@ use Drupal\Component\Plugin\PluginInspectionInterface;
interface LinkGeneratorInterface extends PluginInspectionInterface {
/**
* Get metadata about the entities that the link generator is providing.
*
* @return array
* An array of information about the link generator.
*/
public function getInfo();
/**
* Get a non-executed query for entities of a specific bundle type.
*
* @param string $bundle
* The bundle to query for.
*
* @return \Drupal\Core\Database\Query\SelectInterface
* A query ready for execution.
*/
public function getQuery($bundle);
}
......@@ -23,15 +23,8 @@ class Menu extends LinkGeneratorBase {
/**
* {@inheritdoc}
*/
function get_entities_of_bundle($bundle) {
$query = \Drupal::database()->select('menu_tree', 'm')
->fields('m', array('mlid', 'route_name', 'route_parameters', 'options'))
->condition('menu_name', $bundle)
->condition('enabled', 1)
->condition('route_name', '', '!=');
$info = array(
function getInfo() {
return array(
'field_info' => array(
'entity_id' => 'mlid',
'route_name' => 'route_name',
......@@ -40,6 +33,16 @@ class Menu extends LinkGeneratorBase {
),
'path_info' => array()
);
return array('query' => $query, 'info' => $info);
}
/**
* {@inheritdoc}
*/
public function getQuery($bundle) {
return \Drupal::database()->select('menu_tree', 'm')
->fields('m', array('mlid', 'route_name', 'route_parameters', 'options'))
->condition('menu_name', $bundle)
->condition('enabled', 1)
->condition('route_name', '', '!=');
}
}
......@@ -23,14 +23,8 @@ class NodeType extends LinkGeneratorBase {
/**
* {@inheritdoc}
*/
function get_entities_of_bundle($bundle) {
$query = \Drupal::database()->select('node_field_data', 'n')
->fields('n', array('nid', 'changed'))
->condition('type', $bundle)
->condition('status', 1);
$info = array(
public function getInfo() {
return array(
'field_info' => array(
'entity_id' => 'nid',
'lastmod' => 'changed',
......@@ -40,6 +34,16 @@ class NodeType extends LinkGeneratorBase {
'entity_type' => 'node',
)
);
return array('query' => $query, 'info' => $info);
}
/**
* {@inheritdoc}
*/
public function getQuery($bundle) {
return \Drupal::database()->select('node_field_data', 'n')
->fields('n', array('nid', 'changed'))
->condition('type', $bundle)
->condition('status', 1);
}
}
......@@ -23,13 +23,8 @@ class TaxonomyVocabulary extends LinkGeneratorBase {
/**
* {@inheritdoc}
*/
function get_entities_of_bundle($bundle) {
$query = \Drupal::database()->select('taxonomy_term_field_data', 't')
->fields('t', array('tid', 'changed'))
->condition('vid', $bundle);
$info = array(
public function getInfo() {
return array(
'field_info' => array(
'entity_id' => 'tid',
'lastmod' => 'changed',
......@@ -39,6 +34,15 @@ class TaxonomyVocabulary extends LinkGeneratorBase {
'entity_type' => 'taxonomy_term',
)
);
return array('query' => $query, 'info' => $info);
}
/**
* {@inheritdoc}
*/
public function getQuery($bundle) {
return \Drupal::database()->select('taxonomy_term_field_data', 't')
->fields('t', array('tid', 'changed'))
->condition('vid', $bundle);
}
}
......@@ -24,13 +24,8 @@ class User extends LinkGeneratorBase {
/**
* {@inheritdoc}
*/
function get_entities_of_bundle($bundle) {
$query = \Drupal::database()->select('users_field_data', 'u')
->fields('u', array('uid', 'changed'))
->condition('status', 1);
$info = array(
public function getInfo() {
array(
'field_info' => array(
'entity_id' => 'uid',
'lastmod' => 'changed',
......@@ -38,7 +33,17 @@ class User extends LinkGeneratorBase {
'path_info' => array(
'route_name' => 'entity.user.canonical',
'entity_type' => 'user',
));
return array('query' => $query, 'info' => $info);
)
);
}
/**
* {@inheritdoc}
*/
public function getQuery($bundle) {
return \Drupal::database()->select('users_field_data', 'u')
->fields('u', array('uid', 'changed'))
->condition('status', 1);
}
}
......@@ -93,7 +93,8 @@ class SitemapGenerator {
$instance = $manager->createInstance($link_generator_plugin['id']);
foreach($this->entity_types[$link_generator_plugin['id']] as $bundle => $bundle_settings) {
if ($bundle_settings['index']) {
$operation = $instance->get_entities_of_bundle($bundle);
$operation['info'] = $instance->getInfo();
$operation['query'] = $instance->getQuery($bundle);
$operation['info']['bundle_settings'] = $bundle_settings;
$operations[] = $operation;
}
......
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