Skip to content

Commit 4af02fa

Browse files
committed
separate Dataset buttons form metadata field
1 parent 9ab6be9 commit 4af02fa

File tree

3 files changed

+63
-26
lines changed

3 files changed

+63
-26
lines changed

modules/quanthub_core/quanthub_core.module

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,38 @@ function quanthub_core_language_switch_links_alter(array &$links, $type, Url $ur
279279
}
280280
}
281281
}
282+
283+
/**
284+
* Implements hook_entity_extra_field_info().
285+
*/
286+
function quanthub_core_entity_extra_field_info() {
287+
$extra = [];
288+
289+
$extra['node']['dataset']['display']['dataset_buttons'] = [
290+
'label' => t('Dataset Buttons'),
291+
'description' => t('Download, Explore, and Metadata buttons'),
292+
'weight' => 100,
293+
'visible' => TRUE,
294+
];
295+
296+
return $extra;
297+
}
298+
299+
/**
300+
* Implements hook_ENTITY_TYPE_view().
301+
*/
302+
function quanthub_core_node_view(array &$build, $entity, $display, $view_mode) {
303+
if ($entity->bundle() === 'dataset' && $display->getComponent('dataset_buttons')) {
304+
$build['dataset_buttons'] = [
305+
'#theme' => 'dataset_buttons',
306+
'#urn' => $entity->get('field_quanthub_urn')->value ?? '',
307+
'#langcode' => \Drupal::languageManager()->getCurrentLanguage()->getId(),
308+
'#attached' => [
309+
'library' => [
310+
'quanthub_download_button/download-button',
311+
'quanthub_metadata_button/metadata-button',
312+
],
313+
],
314+
];
315+
}
316+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{#
2+
/**
3+
* Template for Quanthub dataset buttons.
4+
*/
5+
#}
6+
7+
<ul class="flex gap-4 py-4 border-bottom">
8+
<li>
9+
<div class="download_button_id" data-btn-class="primary-button"
10+
data-urn="{{ quanthub_urn }}"></div>
11+
</li>
12+
<li>
13+
<a href="/{{ langcode }}/explorer?urn={{ quanthub_urn }}"
14+
class="secondary-button">
15+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"
16+
xmlns="http://www.w3.org/2000/svg">
17+
<path
18+
d="M8.00001 1.33333C4.32001 1.33333 1.33334 4.31999 1.33334 8C1.33334 11.68 4.32001 14.6667 8.00001 14.6667C11.68 14.6667 14.6667 11.68 14.6667 8C14.6667 4.31999 11.68 1.33333 8.00001 1.33333ZM8.00001 13.3333C5.06001 13.3333 2.66668 10.94 2.66668 8C2.66668 5.06 5.06001 2.66666 8.00001 2.66666C10.94 2.66666 13.3333 5.06 13.3333 8C13.3333 10.94 10.94 13.3333 8.00001 13.3333ZM4.33334 11.6667L9.34001 9.34L11.6667 4.33333L6.66001 6.66L4.33334 11.6667ZM8.00001 7.26666C8.40668 7.26666 8.73334 7.59333 8.73334 8C8.73334 8.40666 8.40668 8.73333 8.00001 8.73333C7.59334 8.73333 7.26668 8.40666 7.26668 8C7.26668 7.59333 7.59334 7.26666 8.00001 7.26666Z"
19+
fill="#424A9C"/>
20+
</svg>
21+
{{ '@explore'|t({'@explore': "Explore" }) }}
22+
</a>
23+
</li>
24+
<li>
25+
<div class="metadata_button_id" data-btn-class="secondary-button"
26+
data-urn="{{ quanthub_urn }}"></div>
27+
</li>
28+
</ul>

themes/quanthub_tailwindcss/templates/field/field--node--field-metadata--dataset--full.html.twig

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
*/
3939
#}
4040

41-
{{ attach_library('quanthub_download_button/download-button') }}
42-
{{ attach_library('quanthub_metadata_button/metadata-button') }}
43-
4441
{%
4542
set classes = [
4643
'field',
@@ -83,26 +80,3 @@
8380
{% endif %}
8481
</div>
8582
{% endif %}
86-
87-
<ul class="flex gap-4 py-4 border-bottom">
88-
<li>
89-
<div class="download_button_id" data-btn-class="primary-button"
90-
data-urn="{{ quanthub_urn }}"></div>
91-
</li>
92-
<li>
93-
<a href="/{{ langcode }}/explorer?urn={{ quanthub_urn }}"
94-
class="secondary-button">
95-
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"
96-
xmlns="http://www.w3.org/2000/svg">
97-
<path
98-
d="M8.00001 1.33333C4.32001 1.33333 1.33334 4.31999 1.33334 8C1.33334 11.68 4.32001 14.6667 8.00001 14.6667C11.68 14.6667 14.6667 11.68 14.6667 8C14.6667 4.31999 11.68 1.33333 8.00001 1.33333ZM8.00001 13.3333C5.06001 13.3333 2.66668 10.94 2.66668 8C2.66668 5.06 5.06001 2.66666 8.00001 2.66666C10.94 2.66666 13.3333 5.06 13.3333 8C13.3333 10.94 10.94 13.3333 8.00001 13.3333ZM4.33334 11.6667L9.34001 9.34L11.6667 4.33333L6.66001 6.66L4.33334 11.6667ZM8.00001 7.26666C8.40668 7.26666 8.73334 7.59333 8.73334 8C8.73334 8.40666 8.40668 8.73333 8.00001 8.73333C7.59334 8.73333 7.26668 8.40666 7.26668 8C7.26668 7.59333 7.59334 7.26666 8.00001 7.26666Z"
99-
fill="#424A9C" />
100-
</svg>
101-
{{ '@explore'|t({'@explore': "Explore" }) }}
102-
</a>
103-
</li>
104-
<li>
105-
<div class="metadata_button_id" data-btn-class="secondary-button"
106-
data-urn="{{ quanthub_urn }}"></div>
107-
</li>
108-
</ul>

0 commit comments

Comments
 (0)