Browse Source

generalized to include taxonomy

main
astanley 2 weeks ago
parent
commit
e58e276157
  1. 60
      src/Controller/MetadataProfileController.php

60
src/Controller/MetadataProfileController.php

@ -194,11 +194,13 @@ class MetadataProfileController extends ControllerBase {
$container->get('entity_type.manager'), $container->get('entity_type.manager'),
); );
} }
/** /**
* Builds a reverse map of field name → indexed field entries across all * Builds a reverse map of field name → indexed field entries across all
* Search API indexes. * Search API indexes.
* *
* Map structure: * Map structure:
*
* @code * @code
* [ * [
* 'field_abstract' => [ * 'field_abstract' => [
@ -241,12 +243,12 @@ class MetadataProfileController extends ControllerBase {
$facetsByFieldId = []; $facetsByFieldId = [];
foreach ($this->allFacets as $facet_id => $facet) { foreach ($this->allFacets as $facet_id => $facet) {
$facetsByFieldId[$facet->get('field_identifier')][] = [ $facetsByFieldId[$facet->get('field_identifier')][] = [
'field_identifier' => $facet->get('field_identifier'), 'field_identifier' => $facet->get('field_identifier'),
'facet_name' => $facet->getName(), 'facet_name' => $facet->getName(),
'facet_machine_name' => $facet_id, 'facet_machine_name' => $facet_id,
'facet_source' => $facet->getFacetSourceId(), 'facet_source' => $facet->getFacetSourceId(),
'url_alias' => $facet->getUrlAlias(), 'url_alias' => $facet->getUrlAlias(),
'block_visible' => $this->getBlockVisible($facet), 'block_visible' => $this->getBlockVisible($facet),
]; ];
} }
@ -329,7 +331,8 @@ class MetadataProfileController extends ControllerBase {
* The bundle configuration object. * The bundle configuration object.
* *
* @return array * @return array
* A render array containing the bundle label, machine name, and description. * A render array containing the bundle label, machine name, and
* description.
*/ */
protected function formatBundle(Config $bundle) { protected function formatBundle(Config $bundle) {
if (str_starts_with($bundle->getName(), 'node.type')) { if (str_starts_with($bundle->getName(), 'node.type')) {
@ -490,8 +493,8 @@ class MetadataProfileController extends ControllerBase {
return [ return [
'in_search_api' => !empty($indexed_fields), 'in_search_api' => !empty($indexed_fields),
'has_facet' => $has_facet, 'has_facet' => $has_facet,
'fields' => $indexed_fields, 'fields' => $indexed_fields,
]; ];
} }
@ -621,24 +624,24 @@ class MetadataProfileController extends ControllerBase {
// Resolve included fields for aggregate / EDTF paths. // Resolve included fields for aggregate / EDTF paths.
$fields_included = match ($property_path) { $fields_included = match ($property_path) {
'aggregated_field' => $field_setting['configuration']['fields'] ?? [], 'aggregated_field' => $field_setting['configuration']['fields'] ?? [],
'edtf_year' => $index_config->get('processor_settings.edtf_year_only.fields') ?? [], 'edtf_year' => $index_config->get('processor_settings.edtf_year_only.fields') ?? [],
'edtf_dates' => $index_config->get('processor_settings.edtf_date_processor.fields') ?? [], 'edtf_dates' => $index_config->get('processor_settings.edtf_date_processor.fields') ?? [],
default => [], default => [],
}; };
// O(1) facet lookup from the pre-built map. // O(1) facet lookup from the pre-built map.
$facets = $facets_by_field_id[$field_setting_name] ?? []; $facets = $facets_by_field_id[$field_setting_name] ?? [];
$has_facet = !empty($facets); $has_facet = !empty($facets);
return [ return [
'search_api_field_name' => $field_setting_name, 'search_api_field_name' => $field_setting_name,
'search_api_field_label' => $field_setting['label'] ?? '', 'search_api_field_label' => $field_setting['label'] ?? '',
'property_path' => $property_path, 'property_path' => $property_path,
'type' => $field_setting['type'] ?? '', 'type' => $field_setting['type'] ?? '',
'index_name' => $index_config->get('name'), 'index_name' => $index_config->get('name'),
'fields_included' => $fields_included, 'fields_included' => $fields_included,
'has_facet' => $has_facet, 'has_facet' => $has_facet,
'facets' => $facets, 'facets' => $facets,
]; ];
} }
@ -810,7 +813,7 @@ class MetadataProfileController extends ControllerBase {
// Default sort if no column has been clicked yet. // Default sort if no column has been clicked yet.
if (!$order) { if (!$order) {
usort($rows, function ($a, $b) { usort($rows, function($a, $b) {
return ($b[11] ?? 0) <=> ($a[11] ?? 0); return ($b[11] ?? 0) <=> ($a[11] ?? 0);
}); });
return; return;
@ -829,7 +832,7 @@ class MetadataProfileController extends ControllerBase {
return; return;
} }
usort($rows, function ($a, $b) use ($column_index, $sort) { usort($rows, function($a, $b) use ($column_index, $sort) {
$a_value = $this->extractSortableValue($a[$column_index] ?? ''); $a_value = $this->extractSortableValue($a[$column_index] ?? '');
$b_value = $this->extractSortableValue($b[$column_index] ?? ''); $b_value = $this->extractSortableValue($b[$column_index] ?? '');
@ -1397,7 +1400,7 @@ class MetadataProfileController extends ControllerBase {
if (is_array($element)) { if (is_array($element)) {
if (isset($element['data']) && array_key_exists('#markup', $element['data'])) { if (isset($element['data']) && array_key_exists('#markup', $element['data'])) {
preg_match('/title=["\']([^"\']*)["\']/', $element['data']['#markup'], $matches); preg_match('/title=["\']([^"\']*)["\']/', $element['data']['#markup'], $matches);
$rows[$row_key][$element_key] = $matches[1] ?? null; $rows[$row_key][$element_key] = $matches[1] ?? NULL;
} }
else { else {
$rows[$row_key][$element_key] = implode('|', $element); $rows[$row_key][$element_key] = implode('|', $element);
@ -1420,22 +1423,22 @@ class MetadataProfileController extends ControllerBase {
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
* The file download response. * The file download response.
*/ */
public function download(NodeTypeInterface $node_type) { public function download(?NodeTypeInterface $node_type = NULL) {
// Rebuild your state from the entity // Rebuild your state from the entity
$this->entityBundle = $node_type->id(); if ($node_type) {
$this->entityTypeBundleOf = $node_type->getEntityType()->getBundleOf(); $this->entityBundle = $node_type->id();
$this->entityTypeBundleOf = $node_type->getEntityType()->getBundleOf();
}
$contentType = $this->entityBundle;
$entityKey = $this->entityTypeBundleOf; $entityKey = $this->entityTypeBundleOf;
$headers = array_map(function($header) {
$headers = array_map(function ($header) {
return is_array($header) && isset($header['data']) ? (string) $header['data'] : (string) $header; return is_array($header) && isset($header['data']) ? (string) $header['data'] : (string) $header;
}, $this->getHeaders()); }, $this->getHeaders());
$metadata_profile = $this->getMetadataProfile(); $metadata_profile = $this->getMetadataProfile();
$rows = $this->getRows($metadata_profile); $rows = $this->getRows($metadata_profile);
$rows = $this->sanitizeRowsForCSV($rows); $rows = $this->sanitizeRowsForCSV($rows);
$filename_slug = "{$entityKey}__{$contentType}.csv"; $filename_slug = "{$entityKey}__{$this->entityBundle}.csv";
$filename = $this->fileSystem->getTempDirectory() . '/' . $filename_slug; $filename = $this->fileSystem->getTempDirectory() . '/' . $filename_slug;
if (file_exists($filename)) { if (file_exists($filename)) {
@ -1613,7 +1616,6 @@ class MetadataProfileController extends ControllerBase {
} }
foreach ($field_definitions as $field_name => $field_definition) { foreach ($field_definitions as $field_name => $field_definition) {
// Only configurable fields (skip base fields like title) // Only configurable fields (skip base fields like title)
if ($field_definition->getFieldStorageDefinition() instanceof \Drupal\Core\Field\BaseFieldDefinition) { if ($field_definition->getFieldStorageDefinition() instanceof \Drupal\Core\Field\BaseFieldDefinition) {
continue; continue;

Loading…
Cancel
Save