You are here

class PathSelection in Multi-path autocomplete 8

Provides specific selection functions for nodes.

Plugin annotation


@MpacSelection(
  id = "path",
  module = "mpac",
  label = @Translation("Path selection"),
  types = {"path"},
  group = "default",
  weight = 1
)

Hierarchy

Expanded class hierarchy of PathSelection

File

lib/Drupal/mpac/Plugin/mpac/selection/PathSelection.php, line 26
Contains \Drupal\mpac\Plugin\mpac\selection\PathSelection.

Namespace

Drupal\mpac\Plugin\mpac\selection
View source
class PathSelection extends SelectionBase {
  public function countMatchingItems($match = NULL, $match_operator = 'CONTAINS') {
    $query = $this
      ->buildQuery($match, $match_operator);
    return $query
      ->count()
      ->execute();
  }
  public function getMatchingItems($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    if (!isset($match)) {
      return array();
    }
    $query = $this
      ->buildQuery($match, $match_operator);
    $result = $query
      ->fields('url_alias')
      ->execute();
    if (empty($result)) {
      return array();
    }
    $matches = array();
    foreach ($result as $data) {
      $matches[$data->source] = sprintf('%s *', $data->alias);
    }
    return $matches;
  }
  private function buildQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = db_select('url_alias');
    if (isset($match)) {
      $query
        ->condition('alias', '%' . $match . '%', 'LIKE');
    }
    return $query;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PathSelection::buildQuery private function
PathSelection::countMatchingItems public function Counts items that matches against the given string. Overrides SelectionBase::countMatchingItems
PathSelection::getMatchingItems public function Returns a list of matching items. Overrides SelectionBase::getMatchingItems
SelectionBase::__construct public function Constructs a SelectionBase object.