Skip to content

Commit

Permalink
Merge pull request #162 from openeuropa/OEL-1552
Browse files Browse the repository at this point in the history
OEL-1552: Theme the person content type.
  • Loading branch information
drishu authored Jul 27, 2022
2 parents 3f7f7b2 + 566f8d0 commit d91499b
Show file tree
Hide file tree
Showing 16 changed files with 743 additions and 5 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"openeuropa/oe_media": "^1.14",
"openeuropa/oe_multilingual": "^1.9",
"openeuropa/oe_paragraphs": "^1.13",
"openeuropa/oe_starter_content": "^1.0.0-beta1",
"openeuropa/oe_starter_content": "1.x-dev",
"openeuropa/task-runner-drupal-project-symlink": "^1.0-beta5",
"phpspec/prophecy-phpunit": "^2",
"symfony/dom-crawler": "^4.4.12"
Expand Down Expand Up @@ -95,9 +95,6 @@
"patches": {
"drupal/entity_reference_revisions": {
"https://www.drupal.org/project/entity_reference_revisions/issues/2937835": "https://www.drupal.org/files/issues/2021-03-26/entity_reference_revisions-field_formatter_label-2937835-36.patch"
},
"openeuropa/oe_starter_content": {
"latest": "https://github.com/openeuropa/oe_starter_content/compare/1.0.0-beta1..OEL-1662.diff"
}
},
"drupal-scaffold": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.full
- field.field.node.oe_sc_person.oe_sc_person_additional_info
- field.field.node.oe_sc_person.oe_sc_person_country
- field.field.node.oe_sc_person.oe_sc_person_documents
- field.field.node.oe_sc_person.oe_sc_person_first_name
- field.field.node.oe_sc_person.oe_sc_person_image
- field.field.node.oe_sc_person.oe_sc_person_last_name
- field.field.node.oe_sc_person.oe_sc_person_occupation
- field.field.node.oe_sc_person.oe_sc_person_position
- field.field.node.oe_sc_person.oe_social_media_links
- field.field.node.oe_sc_person.oe_summary
- node.type.oe_sc_person
module:
- text
- user
id: node.oe_sc_person.full
targetEntityType: node
bundle: oe_sc_person
mode: full
content:
oe_sc_person_additional_info:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 0
region: content
oe_sc_person_documents:
type: entity_reference_entity_view
label: hidden
settings:
view_mode: default
link: true
third_party_settings: { }
weight: 1
region: content
hidden:
langcode: true
links: true
oe_content_content_owner: true
oe_content_legacy_link: true
oe_content_navigation_title: true
oe_content_short_title: true
oe_sc_person_country: true
oe_sc_person_first_name: true
oe_sc_person_image: true
oe_sc_person_last_name: true
oe_sc_person_occupation: true
oe_sc_person_position: true
oe_social_media_links: true
oe_summary: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.oe_w_content_banner
- field.field.node.oe_sc_person.oe_sc_person_additional_info
- field.field.node.oe_sc_person.oe_sc_person_country
- field.field.node.oe_sc_person.oe_sc_person_documents
- field.field.node.oe_sc_person.oe_sc_person_first_name
- field.field.node.oe_sc_person.oe_sc_person_image
- field.field.node.oe_sc_person.oe_sc_person_last_name
- field.field.node.oe_sc_person.oe_sc_person_occupation
- field.field.node.oe_sc_person.oe_sc_person_position
- field.field.node.oe_sc_person.oe_social_media_links
- field.field.node.oe_sc_person.oe_summary
- node.type.oe_sc_person
module:
- address
- text
- user
id: node.oe_sc_person.oe_w_content_banner
targetEntityType: node
bundle: oe_sc_person
mode: oe_w_content_banner
content:
oe_sc_person_country:
type: address_country_default
label: hidden
settings: { }
third_party_settings: { }
weight: 1
region: content
oe_sc_person_occupation:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: 2
region: content
oe_sc_person_position:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: 3
region: content
oe_summary:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 0
region: content
hidden:
langcode: true
links: true
oe_content_content_owner: true
oe_content_legacy_link: true
oe_content_navigation_title: true
oe_content_short_title: true
oe_sc_person_additional_info: true
oe_sc_person_documents: true
oe_sc_person_first_name: true
oe_sc_person_image: true
oe_sc_person_last_name: true
oe_social_media_links: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.oe_sc_person.oe_sc_person_additional_info
- field.field.node.oe_sc_person.oe_sc_person_country
- field.field.node.oe_sc_person.oe_sc_person_documents
- field.field.node.oe_sc_person.oe_sc_person_first_name
- field.field.node.oe_sc_person.oe_sc_person_image
- field.field.node.oe_sc_person.oe_sc_person_last_name
- field.field.node.oe_sc_person.oe_sc_person_occupation
- field.field.node.oe_sc_person.oe_sc_person_position
- field.field.node.oe_sc_person.oe_social_media_links
- field.field.node.oe_sc_person.oe_summary
- node.type.oe_sc_person
module:
- user
id: node.oe_sc_person.teaser
targetEntityType: node
bundle: oe_sc_person
mode: teaser
content:
oe_sc_person_occupation:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: 0
region: content
oe_sc_person_position:
type: string
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
weight: 1
region: content
hidden:
langcode: true
links: true
oe_content_content_owner: true
oe_content_legacy_link: true
oe_content_navigation_title: true
oe_content_short_title: true
oe_sc_person_additional_info: true
oe_sc_person_country: true
oe_sc_person_documents: true
oe_sc_person_first_name: true
oe_sc_person_image: true
oe_sc_person_last_name: true
oe_social_media_links: true
oe_summary: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: OpenEuropa Whitelabel Starter Person
type: module
description: Companion module to OE Person providing styling to nodes.
package: OpenEuropa Whitelabel Theme
core_version_requirement: ^9.2
dependencies:
- oe_whitelabel:oe_whitelabel_helper
- oe_starter_content:oe_starter_content_person

config_devel:
install:
- core.entity_view_display.node.oe_sc_person.full
- core.entity_view_display.node.oe_sc_person.oe_w_content_banner
- core.entity_view_display.node.oe_sc_person.teaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

/**
* @file
* OE Whitelabel theme Person.
*/

declare(strict_types = 1);

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Url;
use Drupal\media\MediaInterface;
use Drupal\media\Plugin\media\Source\Image;
use Drupal\media_avportal\Plugin\media\Source\MediaAvPortalPhotoSource;
use Drupal\oe_bootstrap_theme\ValueObject\ImageValueObject;

/**
* Implements hook_preprocess_HOOK() for Person ct in content banner view mode.
*/
function oe_whitelabel_starter_person_preprocess_node__oe_sc_person__oe_w_content_banner(array &$variables) {
_oe_whitelabel_starter_person_preprocess_image($variables);
_oe_whitelabel_starter_person_social_media_links($variables);
}

/**
* Implements hook_preprocess_HOOK() for Person ct in teaser view mode.
*/
function oe_whitelabel_starter_person_preprocess_node__oe_sc_person__teaser(array &$variables) {
_oe_whitelabel_starter_person_preprocess_image($variables);
}

/**
* Helper function to prepare the image for Person ct.
*
* @param array $variables
* Variables from the theme preprocess function.
*/
function _oe_whitelabel_starter_person_preprocess_image(array &$variables): void {
/** @var \Drupal\node\NodeInterface $node */
$node = $variables['node'];

// Bail out if there is no image present.
if ($node->get('oe_sc_person_image')->isEmpty()) {
return;
}

/** @var \Drupal\media\Entity\Media $media */
$media = $node->get('oe_sc_person_image')->entity;
if (!$media instanceof MediaInterface) {
// The media entity is not available anymore, bail out.
return;
}

// Retrieve the correct media translation.
/** @var \Drupal\media\Entity\Media $media */
$media = \Drupal::service('entity.repository')->getTranslationFromContext($media, $node->language()->getId());
$cacheability = CacheableMetadata::createFromRenderArray($variables);
$cacheability->addCacheableDependency($media);

// Run access checks on the media entity.
$access = $media->access('view', $variables['user'], TRUE);
$cacheability->addCacheableDependency($access);
if (!$access->isAllowed()) {
$cacheability->applyTo($variables);
return;
}

// Get the media source.
$source = $media->getSource();

$is_image = $source instanceof MediaAvPortalPhotoSource || $source instanceof Image;

// If it's not an image bail out.
if (!$is_image) {
$cacheability->applyTo($variables);
return;
}

$thumbnail = $media->get('thumbnail')->first();
$variables['image'] = ImageValueObject::fromImageItem($thumbnail);

$cacheability->applyTo($variables);
}

/**
* Helper function to preprocess the social media links.
*
* @param array $variables
* Variables from the preprocess function.
*/
function _oe_whitelabel_starter_person_social_media_links(array &$variables): void {
/** @var \Drupal\node\NodeInterface $node */
$node = $variables['node'];

$social_links = $node->get('oe_social_media_links')->getValue();

foreach ($social_links as $link) {
$variables['social_links'][] = [
'icon_position' => 'before',
'icon' => [
'path' => $variables['bcl_icon_path'],
'name' => $link['link_type'],
],
'label' => $link['title'],
'path' => Url::fromUri($link['uri'])->toString(),
];
}

}
3 changes: 2 additions & 1 deletion runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ drupal:
- "./vendor/bin/drush en oe_whitelabel_helper -y"
- "./vendor/bin/drush en oe_whitelabel_search -y"
- "./vendor/bin/drush en oe_whitelabel_list_pages -y"
- "./vendor/bin/drush en oe_whitelabel_starter_news -y"
- "./vendor/bin/drush en oe_whitelabel_starter_event -y"
- "./vendor/bin/drush en oe_whitelabel_starter_news -y"
- "./vendor/bin/drush en oe_whitelabel_starter_person -y"
- "./vendor/bin/drush en oe_whitelabel_paragraphs -y"
- "./vendor/bin/drush en toolbar -y"
- "./vendor/bin/drush theme:enable oe_whitelabel -y"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{#
/**
* @file
* Field template for person additional information.
*
* @see ./core/themes/stable/templates/field/field.html.twig
*/
#}
{% if items is not empty %}
<h2 class="mb-4">{{ 'Additional information'|t }}</h2>
<div class="mb-4-5">
{% for item in items %}
{{ item.content }}
{% endfor %}
</div>
{% endif %}


18 changes: 18 additions & 0 deletions templates/content/field--node--oe-sc-person-documents.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{#
/**
* @file
* Field template for person documents.
*
* @see ./core/themes/stable/templates/field/field.html.twig
*/
#}
{% if items is not empty %}
<h2 class="mb-4">{{ 'Related documents'|t }}</h2>
<div class="mb-4-5">
{% for item in items %}
{{ item.content }}
{% endfor %}
</div>
{% endif %}


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{#
/**
* @file
* Field template of the oe_document_reference for the oe_document document.
*
* @see ./core/themes/stable/templates/field/field.html.twig
*/
#}
{% for item in items %}
<div{{ not loop.last ? ' class="mb-3"' }}>
{{ item.content }}
</div>
{% endfor %}
Loading

0 comments on commit d91499b

Please sign in to comment.