Skip to content

Commit

Permalink
Merge pull request #276 from UN-OCHA/berliner/HPC-9916
Browse files Browse the repository at this point in the history
HPC-9916: First draft of meta data in diff displays
  • Loading branch information
berliner authored Dec 9, 2024
2 parents bdc7824 + 66f5b88 commit b2364c2
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
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 > strong {
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 {
color: gray;
}
.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;
}
5 changes: 5 additions & 0 deletions html/modules/custom/ncms_ui/ncms_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ function ncms_ui_preprocess_node(&$variables) {
if (in_array($variables['elements']['#view_mode'], ['teaser', 'teaser_card'])) {
$variables['page'] = TRUE;
}
$route_match = \Drupal::routeMatch();
$node = $variables['node'];
if ($route_match->getRouteName() == 'diff.revisions_diff' && $node instanceof ContentInterface) {
$variables['diff_metadata'] = $node->buildMetaDataForDiff();
}
}

/**
Expand Down
39 changes: 39 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 @@ -2,6 +2,7 @@

namespace Drupal\ncms_ui\Entity\Content;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Datetime\DrupalDateTime;
Expand Down Expand Up @@ -340,6 +341,44 @@ public function preSave(EntityStorageInterface $storage) {
$this->setRevisionTranslationAffectedEnforced(TRUE);
}

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

$meta_fields = [
'status',
'field_short_title',
'field_computed_tags',
'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',
]);
if ($field_name == 'field_computed_tags' && !empty($build[$field_name][0]['#markup'])) {
$build[$field_name][0]['#markup'] = implode(', ', explode(',', $build[$field_name][0]['#markup']));
}
}
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 diff_metadata %}
{{ diff_metadata }}
{% endif %}
<header class="gho-article__header">
{{ hero_image }}
<div class="gho-article__heading content-width content-width--reading">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
]
%}
<article{{ attributes.addClass(classes) }}>
{% if diff_metadata %}
{{ diff_metadata }}
{% endif %}
<header class="gho-article__header">
{{ hero_image }}
<div class="gho-article__heading content-width content-width--reading">
Expand Down

0 comments on commit b2364c2

Please sign in to comment.