You are here

function _elasticsearch_connector_views_handle_fields in Elasticsearch Connector 8.7

Same name and namespace in other branches
  1. 8.2 modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc \_elasticsearch_connector_views_handle_fields()
  2. 8.5 modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc \_elasticsearch_connector_views_handle_fields()
  3. 8.6 modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc \_elasticsearch_connector_views_handle_fields()
  4. 7.5 modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc \_elasticsearch_connector_views_handle_fields()
  5. 7 modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc \_elasticsearch_connector_views_handle_fields()
  6. 7.2 modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc \_elasticsearch_connector_views_handle_fields()

Handle the fields mapping and handle nested data types.

Parameters

string $base_table: The base table value.

array $data: Data array.

array $fields: Fields array.

string $base_field_name: Base field name.

1 call to _elasticsearch_connector_views_handle_fields()
elasticsearch_connector_views_views_data in modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc
Implements hook_views_data().

File

modules/elasticsearch_connector_views/elasticsearch_connector_views.views.inc, line 97
Views hook implementations for the Search API module.

Code

function _elasticsearch_connector_views_handle_fields($base_table, &$data, $fields, $base_field_name = '') {
  if (!empty($fields)) {
    foreach ($fields as $field_name => $field) {

      // TODO: Restrict some fields if needed.
      // TODO: Handle boolean.
      // TODO: Handle the cases with analyzed and not analyzed.
      if (empty($field['type']) && isset($field['properties'])) {
        $field_type = 'object';
      }
      else {
        $field_type = $field['type'];
      }
      $filter_handler = 'elasticsearch_connector_views_standard';
      $field_handler = 'elasticsearch_connector_views_standard';
      $set = TRUE;
      switch ($field_type) {
        case 'object':
          if (!empty($field['properties'])) {
            _elasticsearch_connector_views_handle_fields($base_table, $data, $field['properties'], $base_field_name . $field_name . '.');
          }
          $set = FALSE;
          break;
        case 'date':
          $filter_handler = 'elasticsearch_connector_views_date';
          $field_handler = 'elasticsearch_connector_views_date';
          break;
        case 'boolean':
          $filter_handler = 'elasticsearch_connector_views_boolean';
          $field_handler = 'elasticsearch_connector_views_boolean';
          break;

        // TODO: Handle the keyword also for the text fields!
        case 'text':
        case 'string':
        case 'keyword':

          // TODO: Handle the analyser and non_analyzed fields.
          // TODO: For analysed fields we need to do fulltext search.
          if (\Drupal::moduleHandler()
            ->moduleExists('views_autocomplete_filters')) {

            // TODO: Handle autocomplete.

            //$filter_handler = 'elasticsearch_connector_views_handler_filter_string_autocomplete';
          }
          else {
            $field_handler = 'elasticsearch_connector_views_markup';
            $filter_handler = 'elasticsearch_connector_views_string';
          }
          break;

        // Handle numeric filter type.
        case 'integer':
        case 'long':
        case 'float':
        case 'double':
          $filter_handler = 'elasticsearch_connector_views_numeric';
          $field_handler = 'elasticsearch_connector_views_numeric';
          break;
      }
      if ($set) {
        $data[$base_table][$base_field_name . $field_name] = array(
          'title' => $base_field_name . $field_name,
          'help' => $base_field_name . $field_name,
          'field' => array(
            'id' => $field_handler,
            'click sortable' => TRUE,
          ),
          'filter' => array(
            'id' => $filter_handler,
          ),
          'sort' => array(
            'id' => 'standard',
          ),
          // TODO: Handle the argument class.
          'argument' => array(
            'id' => 'standard',
          ),
        );
      }
    }
  }
}