search_api-8.x-1.15/tests/search_api_test_views/search_api_test_views.module

tests/search_api_test_views/search_api_test_views.module
<?php

/**
 * @file
 * Contains hook implementations for the Search API Views Test module.
 */

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\search_api\Query\QueryInterface;

/**
 * Implements hook_search_api_query_alter().
 *
 * Prints the contents of the "search_api_retrieved_field_values" query option
 * to the page (if present) so it can be checked by the testing code.
 */
function search_api_test_views_search_api_query_alter(QueryInterface $query) {
  $fields = $query->getOption('search_api_retrieved_field_values');
  if ($fields) {
    \Drupal::messenger()->addStatus("'" . implode("' '", $fields) . "'");
  }
}

/**
 * Implements hook_entity_type_alter().
 */
function search_api_test_views_entity_type_alter(array &$entity_types) {
  // We need list builder for entity type in order to test operations column.
  if (!empty($entity_types['entity_test_mulrev_changed'])) {
    $entity_types['entity_test_mulrev_changed']
      ->setListBuilderClass(EntityListBuilder::class);
  }
}

/**
 * Implements hook_entity_operation().
 */
function search_api_test_views_entity_operation(EntityInterface $entity) {
  if ($entity->getEntityTypeId() !== 'entity_test_mulrev_changed') {
    return [];
  }

  // For testing purpose we want to have one entity without operations.
  if ($entity->id() == 2) {
    return [];
  }

  $operations['edit'] = [
    'title' => t('Edit'),
    'url' => $entity->toUrl('edit-form'),
    'weight' => 0,
  ];
  $operations['delete'] = [
    'title' => t('Delete'),
    'url' => $entity->toUrl('delete-form'),
    'weight' => 1,
  ];

  return $operations;
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc