<?php

final class PhabricatorSearchDocumentTypeDatasource
  extends PhabricatorTypeaheadDatasource {

  public function getBrowseTitle() {
    return pht('Browse Document Types');
  }

  public function getPlaceholderText() {
    return pht('Select a document type...');
  }

  public function getDatasourceApplicationClass() {
    return 'PhabricatorSearchApplication';
  }

  public function loadResults() {
    $results = $this->buildResults();
    return $this->filterResultsAgainstTokens($results);
  }

  public function renderTokens(array $values) {
    return $this->renderTokensFromResults($this->buildResults(), $values);
  }

  private function buildResults() {
    $types =
      PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes();

    $icons = mpull(
      PhabricatorPHIDType::getAllTypes(),
      'getTypeIcon',
      'getTypeConstant');

    $results = array();
    foreach ($types as $type => $name) {
      $results[$type] = id(new PhabricatorTypeaheadResult())
        ->setPHID($type)
        ->setName($name)
        ->setIcon(idx($icons, $type));
    }

    return $results;
  }

}

<?php

final class PhabricatorSearchDocumentTypeDatasource
  extends PhabricatorTypeaheadDatasource {

  public function getBrowseTitle() {
    return pht('Browse Document Types');
  }

  public function getPlaceholderText() {
    return pht('Select a document type...');
  }

  public function getDatasourceApplicationClass() {
    return 'PhabricatorSearchApplication';
  }

  public function loadResults() {
    $results = $this->buildResults();
    return $this->filterResultsAgainstTokens($results);
  }

  public function renderTokens(array $values) {
    return $this->renderTokensFromResults($this->buildResults(), $values);
  }

  private function buildResults() {
    $viewer = $this->getViewer();
    $types =
      PhabricatorSearchApplicationSearchEngine::getIndexableDocumentTypes(
        $viewer);

    $icons = mpull(
      PhabricatorPHIDType::getAllTypes(),
      'getTypeIcon',
      'getTypeConstant');

    $results = array();
    foreach ($types as $type => $name) {
      $results[$type] = id(new PhabricatorTypeaheadResult())
        ->setPHID($type)
        ->setName($name)
        ->setIcon(idx($icons, $type));
    }

    return $results;
  }

}

Remove unused apps from the DocumentType typeahead
Remove unused apps from the DocumentType typeahead

Summary: Ref T10951. This diff removes uninstalled applications from the result set for DocumentType restults

Test Plan: Uninstall an application (diviner for example), then go to the document type search menu and ensure that the uninstalled application doesn't show up.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley

Maniphest Tasks: T10951

Differential Revision: https://secure.phabricator.com/D16445
