Skip to content

Commit

Permalink
EWPP-2016: Improve display of person teaser.
Browse files Browse the repository at this point in the history
  • Loading branch information
imanoleguskiza authored and 22Alexandra committed Mar 23, 2022
1 parent a8803c1 commit 22991c5
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 32 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"openeuropa/rdf_skos": "^1.0",
"openeuropa/task-runner-drupal-project-symlink": "^1.0-beta5",
"phpspec/prophecy-phpunit": "^2",
"symfony/dom-crawler": "^4.4.12"
"symfony/dom-crawler": "^4.4.12",
"phpmd/phpmd": "2.11.1"
},
"scripts": {
"post-install-cmd": "./vendor/bin/run drupal:site-setup",
Expand Down Expand Up @@ -115,7 +116,8 @@
"Explicit minimum version requirement of drupal/ctools module due to D9.2 compatability.",
"Explicit minimum version requirement of behat library due to PHP compatibility.",
"Explicit requirement for egulias/email-validator due to https://www.drupal.org/project/drupal/issues/3061074#comment-14300579. It can be removed when Drupal core 9.2 support is droppped.",
"Explicit minimum version requirement for symfony/dom-crawler due to its lower versions using the deprecated function libxml_disable_entity_loader() in PHP8."
"Explicit minimum version requirement for symfony/dom-crawler due to its lower versions using the deprecated function libxml_disable_entity_loader() in PHP8.",
"Explicit requirement for phpmd since version 2.7 is installed after latest composer update"
]
},
"config": {
Expand Down
14 changes: 14 additions & 0 deletions modules/oe_theme_content_person/oe_theme_content_person.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ declare(strict_types = 1);
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;

/**
* Implements hook_theme().
*/
function oe_theme_content_person_theme() {
return [
'oe_theme_content_person_job_list' => [
'variables' => [
'simple' => TRUE,
'items' => [],
],
],
];
}

/**
* Implements hook_preprocess_HOOK().
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,45 @@ public function viewElements(ContentEntityInterface $entity) {
return [];
}

$pattern = [
'#type' => 'pattern',
'#id' => 'field_list',
'#variant' => 'horizontal',
'#fields' => [
'items' => [],
],
];

$cacheable_metadata = CacheableMetadata::createFromRenderArray($pattern);
$cacheable_metadata = new CacheableMetadata();
$cacheable_metadata->addCacheableDependency($entity);

$job_list = [
'#theme' => 'oe_theme_content_person_job_list',
'#items' => [],
];
// Prepare person jobs to be shown in the field list pattern.
$view_builder = $this->entityTypeManager->getViewBuilder('oe_person_job');
foreach ($entity->get('oe_person_jobs')->referencedEntities() as $person_job) {
// Retrieve the translation of the person job entity.
$person_job = $this->entityRepository->getTranslationFromContext($person_job);

// Body has to be filled with at least empty space. Otherwise whole line
// will be hidden.
$body = ' ';
$body = '';
if (!$person_job->get('oe_description')->isEmpty()) {
$body = $view_builder->viewField($person_job->get('oe_description'), [
'label' => 'hidden',
]);
$job_list['#simple'] = FALSE;
}
$pattern['#fields']['items'][] = [
$job_list['#items'][] = [
'label' => $person_job->label(),
'body' => $body,
];
$cacheable_metadata->addCacheableDependency($person_job);
}

$pattern = [
'#type' => 'pattern',
'#id' => 'field_list',
'#variant' => 'horizontal',
'#fields' => [
'items' => [
[
'label' => $this->t('Responsibilities'),
'body' => $job_list,
],
],
],
];
$cacheable_metadata->applyTo($pattern);
return $pattern;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{#
/**
* @file
* Theme template for Person job list extra field.
*
* @see \Drupal\oe_theme_content_person\Plugin\ExtraField\Display\PersonJobListExtraField::viewElements()
*/
#}
{% if simple %}
<ul class="ecl-unordered-list">
{% for item in items %}
<li class="ecl-unordered-list__item">
{{ item.label}}
</li>
{% endfor %}
</ul>
{% else %}
{% for item in items %}
<div class="ecl-u-type-m ecl-u-type-bold ecl-u-mb-xs">{{ item.label }}</div>
{% if item.body %}
<div class="ecl-u-mb-xs">{{ item.body }}</div>
{% endif %}
{% endfor %}
{% endif %}

3 changes: 2 additions & 1 deletion sass/compositions/_content_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.ecl-content-item {
&__meta {
text-transform: uppercase;
line-height: 1.25rem!important;
}
&__description {
p {
Expand All @@ -18,7 +19,7 @@
a {
color: map.get(theme.$color, 'blue-100');
font-weight: map.get(theme.$font-weight, 'bold')!important;
font: map.get(theme.$font-prolonged, 'm');
font: map.get(theme.$font-prolonged, 'xl');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* @see ./core/themes/stable/templates/field/field.html.twig
*/
#}
{%- include 'field--multiple-values--pipe-separated.html.twig' -%}
{%- include 'field--multiple-values--comma-separated.html.twig' -%}
20 changes: 7 additions & 13 deletions tests/src/Kernel/PersonRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function testTeaser(): void {
'items' => [
[
'label' => 'Departments',
'body' => 'Audit Board of the European Communities | Arab Common Market',
'body' => 'Audit Board of the European Communities, Arab Common Market',
],
],
]),
Expand Down Expand Up @@ -262,8 +262,8 @@ public function testTeaser(): void {
$expected_values['additional_information'][1] = new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => '(Acting) Adviser',
'body' => 'Description job_1',
'label' => 'Responsibilities',
'body' => '(Acting) AdviserDescription job_1',
],
],
]);
Expand All @@ -275,11 +275,8 @@ public function testTeaser(): void {
$expected_values['additional_information'][1] = new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => '(Acting) Adviser',
'body' => 'Description job_1',
], [
'label' => 'Chief Adviser',
'body' => 'Description job_2',
'label' => 'Responsibilities',
'body' => '(Acting) AdviserDescription job_1Chief AdviserDescription job_2',
],
],
]);
Expand Down Expand Up @@ -345,11 +342,8 @@ public function testTeaser(): void {
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Singer',
'body' => 'Description job_1',
], [
'label' => 'Dancer',
'body' => 'Description job_2',
'label' => 'Responsibilities',
'body' => 'SingerDescription job_1DancerDescription job_2',
],
],
]),
Expand Down

0 comments on commit 22991c5

Please sign in to comment.