-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from openeuropa/OEL-1552
OEL-1552: Theme the person content type.
- Loading branch information
Showing
16 changed files
with
743 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...telabel_starter_person/config/install/core.entity_view_display.node.oe_sc_person.full.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
69 changes: 69 additions & 0 deletions
69
..._person/config/install/core.entity_view_display.node.oe_sc_person.oe_w_content_banner.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
55 changes: 55 additions & 0 deletions
55
...label_starter_person/config/install/core.entity_view_display.node.oe_sc_person.teaser.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
modules/oe_whitelabel_starter_person/oe_whitelabel_starter_person.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
109 changes: 109 additions & 0 deletions
109
modules/oe_whitelabel_starter_person/oe_whitelabel_starter_person.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
templates/content/field--node--oe-sc-person-additional-info.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
templates/content/field--node--oe-sc-person-documents.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
templates/content/field--oe-document-reference--oe-document--oe-document.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
Oops, something went wrong.