Commit 2e83a6c5 authored by Sam Becker's avatar Sam Becker Committed by Pawel G
Browse files

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
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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);

}
+13 −10
Original line number Diff line number Diff line
@@ -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', '', '!=');
  }
}
+13 −9
Original line number Diff line number Diff line
@@ -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);
  }

}
+12 −8
Original line number Diff line number Diff line
@@ -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);
  }

}
+14 −9
Original line number Diff line number Diff line
@@ -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);
  }

}
Loading