diff --git a/modules/quanthub_core/quanthub_core.module b/modules/quanthub_core/quanthub_core.module index 80551c43..57121a6b 100644 --- a/modules/quanthub_core/quanthub_core.module +++ b/modules/quanthub_core/quanthub_core.module @@ -124,6 +124,13 @@ function quanthub_core_theme() { ], 'template' => 'powerbi-embed-formatter', ], + 'dataset_buttons' => [ + 'variables' => [ + 'quanthub_urn' => NULL, + 'langcode' => NULL, + ], + 'template' => 'dataset-buttons', + ], ]; } @@ -279,3 +286,32 @@ function quanthub_core_language_switch_links_alter(array &$links, $type, Url $ur } } } + +/** + * Implements hook_entity_extra_field_info(). + */ +function quanthub_core_entity_extra_field_info() { + $extra = []; + + $extra['node']['dataset']['display']['dataset_buttons'] = [ + 'label' => t('Dataset Buttons'), + 'description' => t('Download, Explore, and Metadata buttons'), + 'weight' => 100, + 'visible' => TRUE, + ]; + + return $extra; +} + +/** + * Implements hook_ENTITY_TYPE_view(). + */ +function quanthub_core_node_view(array &$build, $entity, $display, $view_mode) { + if ($entity->bundle() === 'dataset' && $display->getComponent('dataset_buttons')) { + $build['dataset_buttons'] = [ + '#theme' => 'dataset_buttons', + '#quanthub_urn' => $entity->get('field_quanthub_urn')->value ?? '', + '#langcode' => \Drupal::languageManager()->getCurrentLanguage()->getId(), + ]; + } +} diff --git a/modules/quanthub_core/templates/dataset-buttons.html.twig b/modules/quanthub_core/templates/dataset-buttons.html.twig new file mode 100644 index 00000000..65dde9ad --- /dev/null +++ b/modules/quanthub_core/templates/dataset-buttons.html.twig @@ -0,0 +1,17 @@ +{# +/** + * @file + * Minimal template for Dataset buttons. + * + * This template provides basic structure. Theme should override for styling. + * + */ +#} + +
diff --git a/modules/quanthub_download_button/quanthub_download_button.module b/modules/quanthub_download_button/quanthub_download_button.module deleted file mode 100644 index 1e23762d..00000000 --- a/modules/quanthub_download_button/quanthub_download_button.module +++ /dev/null @@ -1,36 +0,0 @@ -getType() == 'dataset' - ) { - $variables['quanthub_urn'] = $entity->field_quanthub_urn->getString(); - } - } -} - -/** - * Preprocess node. - */ -function quanthub_download_button_preprocess_node(&$variables) { - $node = $variables['node']; - if ( - $node instanceof NodeInterface && - $node->getType() == 'dataset' - ) { - $variables['quanthub_urn'] = $node->field_quanthub_urn->getString(); - } -} diff --git a/themes/quanthub_tailwindcss/templates/dataset-buttons.html.twig b/themes/quanthub_tailwindcss/templates/dataset-buttons.html.twig new file mode 100644 index 00000000..ed4c6b19 --- /dev/null +++ b/themes/quanthub_tailwindcss/templates/dataset-buttons.html.twig @@ -0,0 +1,35 @@ +{# +/** + * Template for Quanthub dataset buttons. + */ +#} + +{{ attach_library('quanthub_download_button/download-button') }} +{{ attach_library('quanthub_metadata_button/metadata-button') }} + +