You are here

function search_api_solr_entity_operation in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 search_api_solr.module \search_api_solr_entity_operation()
  2. 8.2 search_api_solr.module \search_api_solr_entity_operation()

Implements hook_entity_operation().

Adds an operation to Solr servers to directly generate and download a config.

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

Return value

array

Throws

\Drupal\search_api\SearchApiException

File

./search_api_solr.module, line 617

Code

function search_api_solr_entity_operation(EntityInterface $entity) {
  $operations = [];
  if ($entity instanceof ServerInterface && $entity
    ->getBackend() instanceof SolrBackendInterface) {
    $operations['get_config_zip'] = [
      'title' => t('Get config.zip'),
      'url' => Url::fromRoute('solr_configset.config_zip', [
        'search_api_server' => $entity
          ->id(),
      ]),
      'weight' => 50,
    ];
  }
  elseif ($entity instanceof IndexInterface) {
    if ($entity
      ->isServerEnabled() && $entity
      ->getServerInstance()
      ->getBackend() instanceof SolrBackendInterface && !$entity
      ->isValidDatasource('solr_multisite_document')) {
      $operations['clone_for_multisite'] = [
        'title' => t('Clone for Multisite'),
        'url' => Url::fromRoute('entity.search_api_index.solr_multisite_clone_form', [
          'search_api_index' => $entity
            ->id(),
        ]),
        'weight' => 50,
      ];
    }
    elseif ($entity
      ->isValidDatasource('solr_multisite_document')) {
      $operations['update_for_multisite'] = [
        'title' => t('Update for Multisite'),
        // @todo
        'url' => Url::fromRoute('entity.search_api_index.solr_multisite_update_form', [
          'search_api_index' => $entity
            ->id(),
        ]),
        'weight' => 50,
      ];
    }
  }
  return $operations;
}