You are here

class SiteNameLink in Search API Field Map 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/processor/SiteNameLink.php \Drupal\search_api_field_map\Plugin\search_api\processor\SiteNameLink
  2. 8 src/Plugin/search_api/processor/SiteNameLink.php \Drupal\search_api_field_map\Plugin\search_api\processor\SiteNameLink
  3. 8.2 src/Plugin/search_api/processor/SiteNameLink.php \Drupal\search_api_field_map\Plugin\search_api\processor\SiteNameLink

Links the base url with the site name.

Plugin annotation


@SearchApiProcessor(
  id = "site_name_link",
  label = @Translation("Site name link"),
  description = @Translation("Links the base url with the site name."),
  stages = {
    "postprocess_query" = 0
  }
)

Hierarchy

  • class \Drupal\search_api_field_map\Plugin\search_api\processor\SiteNameLink extends \Drupal\search_api\Processor\ProcessorPluginBase implements PluginFormInterface uses \Drupal\search_api\Plugin\PluginFormTrait

Expanded class hierarchy of SiteNameLink

File

src/Plugin/search_api/processor/SiteNameLink.php, line 25

Namespace

Drupal\search_api_field_map\Plugin\search_api\processor
View source
class SiteNameLink extends ProcessorPluginBase implements PluginFormInterface {
  use PluginFormTrait;

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['description'] = [
      '#type' => 'item',
      '#description' => $this
        ->t('This processor provides no configuration options.'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function postprocessSearchResults(ResultSetInterface $results) {
    $query = $results
      ->getQuery();
    if (!$results
      ->getResultCount()) {
      return;
    }
    $result_items = $results
      ->getResultItems();
    foreach ($result_items as $key => $item) {
      $site = $item
        ->getExtraData('search_api_solr_document')['site'];
      $url = Url::fromUri($site);
      $name = $item
        ->getField('site_name')
        ->getValues()[0];
      $link = Link::fromTextAndUrl(t($name), $url)
        ->toString();
      $item
        ->getField('site_name')
        ->setValues([
        $link,
      ]);
    }
  }

}

Members