You are here

class LinkitSearchPluginTaxonomy_term in Linkit 7.3

Reprecents a Linkit term search plugin.

Hierarchy

Expanded class hierarchy of LinkitSearchPluginTaxonomy_term

File

plugins/linkit_search/taxonomy_term.class.php, line 10
Define Linkit term search plugin class.

View source
class LinkitSearchPluginTaxonomy_term extends LinkitSearchPluginEntity {

  /**
   * Overrides LinkitSearchPluginEntity::__construct().
   */
  function __construct($plugin, $profile) {

    /**
     * The term entity doesn't use the same column name as in the entity keys
     * bundle definition, so lets add it our self.
     */
    $this->entity_key_bundle = 'vid';
    parent::__construct($plugin, $profile);
  }

  /**
   * Overrides LinkitSearchPluginEntity::createDescription().
   */
  function createDescription($data) {
    $description = token_replace(check_plain($this->conf['result_description']), array(
      'term' => $data,
    ), array(
      'clear' => TRUE,
    ));
    return $description;
  }

  /**
   * Overrides LinkitSearchPluginEntity::createGroup().
   */
  function createGroup($entity) {

    // Get the entity label.
    $group = $this->entity_info['label'];
    if (isset($this->conf['group_by_bundle']) && $this->conf['group_by_bundle']) {
      $bundles = $this->entity_info['bundles'];
      $bundle_name = $bundles[$entity->vocabulary_machine_name]['label'];
      $group .= ' - ' . check_plain($bundle_name);
    }
    return $group;
  }

  /**
   * Overrides LinkitSearchPluginEntity::fetchResults().
   */
  function fetchResults($search_string) {

    // The term entity doesn't use the entity keys bundle definition, its using
    // the vid instead, so lets 'translate' the bundle names to vids.
    if (isset($this->entity_key_bundle) && isset($this->conf['bundles'])) {
      $bundles = array_filter($this->conf['bundles']);

      // Get all vocabularies.
      $vocabularies = taxonomy_vocabulary_get_names();

      // Temp storage for values.
      $tmp_bundles = array();
      foreach ($bundles as $bundle) {
        $tmp_bundles[] = $vocabularies[$bundle]->{$this->entity_key_bundle};
      }

      // Assign the new values as the bundles.
      $this->conf['bundles'] = $tmp_bundles;
    }

    // Call the parent.
    return parent::fetchResults($search_string);
  }

  /**
   * Overrides LinkitSearchPlugin::buildSettingsForm().
   */
  function buildSettingsForm() {
    $form = parent::buildSettingsForm();

    // The entity plugin uses the entity name for the #token_types, but terms
    // is a special case, its name is "Taxonomy_term" and the tokens are defined
    // (in the taxonomy module) with just "term".
    // If the token modules is installed.
    if (isset($form[$this->plugin['name']]['token_help']['help']['#token_types'])) {
      $form[$this->plugin['name']]['token_help']['help']['#token_types'] = array(
        'term',
      );
    }
    else {

      // Get supported tokens for the term entity type.
      $tokens = linkit_extract_tokens('term');
      $form[$this->plugin['name']]['result_description']['#description'] = t('Available tokens: %tokens.', array(
        '%tokens' => implode(', ', $tokens),
      ));
    }
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkitSearchPlugin::$plugin protected property The plugin definition for this instance.
LinkitSearchPlugin::$profile protected property The profile instance for this instance.
LinkitSearchPlugin::broken public function Determine if the handler is considered 'broken', meaning it's a a placeholder used when a handler can't be found. 1
LinkitSearchPlugin::factory public static function Implements LinkitSearchPluginInterface::factory(). Overrides LinkitSearchPluginInterface::factory
LinkitSearchPlugin::ui_description public function Implements LinkitSearchPluginInterface::ui_description(). Overrides LinkitSearchPluginInterface::ui_description 2
LinkitSearchPlugin::ui_title public function Implements LinkitSearchPluginInterface::ui_title(). Overrides LinkitSearchPluginInterface::ui_title 2
LinkitSearchPluginEntity::$conf property Plugin specific settings.
LinkitSearchPluginEntity::$entity_field_label property The name of the property that contains the entity label.
LinkitSearchPluginEntity::$entity_info property The entity info array of an entity type.
LinkitSearchPluginEntity::$entity_key_bundle property The name of the property of the bundle object that contains the name of the bundle object.
LinkitSearchPluginEntity::$query property Entity field query instance.
LinkitSearchPluginEntity::createLabel function Create a label of an entity.
LinkitSearchPluginEntity::createPath function Create an uri for an entity. 1
LinkitSearchPluginEntity::createRowClass function Create a row class to append to the search result row. 1
LinkitSearchPluginEntity::getQueryInstance function Start a new EntityFieldQuery instance. 2
LinkitSearchPluginTaxonomy_term::buildSettingsForm function Overrides LinkitSearchPlugin::buildSettingsForm(). Overrides LinkitSearchPluginEntity::buildSettingsForm
LinkitSearchPluginTaxonomy_term::createDescription function Overrides LinkitSearchPluginEntity::createDescription(). Overrides LinkitSearchPluginEntity::createDescription
LinkitSearchPluginTaxonomy_term::createGroup function Overrides LinkitSearchPluginEntity::createGroup(). Overrides LinkitSearchPluginEntity::createGroup
LinkitSearchPluginTaxonomy_term::fetchResults function Overrides LinkitSearchPluginEntity::fetchResults(). Overrides LinkitSearchPluginEntity::fetchResults
LinkitSearchPluginTaxonomy_term::__construct function Overrides LinkitSearchPluginEntity::__construct(). Overrides LinkitSearchPluginEntity::__construct