Browse Source

generalized to include taxonomy

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

22
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' => [
@ -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')) {
@ -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
if ($node_type) {
$this->entityBundle = $node_type->id(); $this->entityBundle = $node_type->id();
$this->entityTypeBundleOf = $node_type->getEntityType()->getBundleOf(); $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