Skip to content

Commit

Permalink
HPC-9916: First draft of meta data in diff displays
Browse files Browse the repository at this point in the history
  • Loading branch information
berliner committed Dec 2, 2024
1 parent e13133e commit 2f76a79
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
30 changes: 29 additions & 1 deletion html/modules/custom/ncms_ui/css/diff.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
.ncms-node-diff #main-content {
padding-block-start: 0;
}
.ncms-node-diff .diff-header {
.ncms-node-diff .diff-header,
.ncms-node-diff .metadata-wrapper {
margin-bottom: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--cd-blue-grey--dark);
}

.ncms-node-diff .diff-header label,
.ncms-node-diff .metadata-wrapper label {
font-weight: bold;
}

.ncms-node-diff .diff-header .diff-revision__items .diff-revision__items-group:first-child {
background-color: #cfc;
}
.ncms-node-diff .diff-header .diff-revision__items .diff-revision__items-group:last-child {
background-color: #fcc;
}

.ncms-node-diff .diff-controls {
display: none;
}
Expand All @@ -19,3 +32,18 @@
margin: 2rem 0;
display: block;
}

.ncms-node-diff .metadata-wrapper .field--label-inline > .field__label,
.ncms-node-diff .metadata-wrapper .field--label-inline > .field__item {
display: inline;
}
.ncms-node-diff .metadata-wrapper .field--label-inline > .field__label {
font-weight: bold;
}
.ncms-node-diff .metadata-wrapper .field--label-inline > .field__label::after {
content: ":";
}
.ncms-node-diff .metadata-wrapper .field--type-text-long .field__item p {
display: inline;
margin-left: 0.3rem;
}
35 changes: 35 additions & 0 deletions html/modules/custom/ncms_ui/src/Entity/Content/ContentBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,41 @@ public function preSave(EntityStorageInterface $storage) {
$this->setRevisionTranslationAffectedEnforced(TRUE);
}

/**
* {@inheritdoc}
*/
public function buildMetaDataForDiff() {
$build = [
'#type' => 'container',
'#attributes' => [
'class' => ['metadata-wrapper'],
],
];
$build['header'] = [
'#type' => 'label',
'#title' => $this->t('Meta data'),
'#title_display' => 'before',
];

$meta_fields = [
'field_short_title',
'field_computed_tags',
'field_automatically_visible',
'field_summary',
'field_author',
'field_pdf',
];
foreach ($meta_fields as $field_name) {
if (!$this->hasField($field_name)) {
continue;
}
$build[$field_name] = $this->get($field_name)->view([
'label' => 'inline',
]);
}
return $build;
}

/**
* Get the route match service.
*
Expand Down
8 changes: 8 additions & 0 deletions html/modules/custom/ncms_ui/src/Entity/ContentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ public function isDeleted();
*/
public function getEntityOperations();

/**
* Build the metadata used for diff displays.
*
* @return array
* A render array.
*/
public function buildMetaDataForDiff();

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
]
%}
<article{{ attributes.addClass(classes) }}>
{% if content.diff_metadata %}
{{ content.diff_metadata }}
{% endif %}
<header class="gho-article__header">
{{ hero_image }}
<div class="gho-article__heading content-width content-width--reading">
Expand All @@ -115,7 +118,7 @@
{% endif %}

<div{{ content_attributes.addClass('node__content').addClass('gho-article__content') }}>
{{ content|without(['field_hero_image', 'field_appeals']) }}
{{ content|without(['field_hero_image', 'field_appeals', 'diff_metadata']) }}
</div>

</article>
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
]
%}
<article{{ attributes.addClass(classes) }}>
{% if content.diff_metadata %}
{{ content.diff_metadata }}
{% endif %}
<header class="gho-article__header">
{{ hero_image }}
<div class="gho-article__heading content-width content-width--reading">
Expand All @@ -114,7 +117,7 @@
{% endif %}

<div{{ content_attributes.addClass('node__content').addClass('gho-article__content') }}>
{{ content|without(['field_hero_image']) }}
{{ content|without(['field_hero_image', 'diff_metadata']) }}
</div>

</article>

0 comments on commit 2f76a79

Please sign in to comment.