Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEL-1552: Theme the person content type #162

Merged
merged 44 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
668d5cf
OEL-1552: Add to composer required changes from oe_content and oe_sta…
escuriola Jun 29, 2022
7caf38c
OEL-1552: Create whitelabel module for person.
escuriola Jun 29, 2022
4af6f4d
OEL-1552: Create templates for person, work in progress.
escuriola Jun 29, 2022
3dd3efe
OEL-1552: Activate whitelabel person module on site installation.
escuriola Jun 29, 2022
196b265
OEL-1552: Bring the Person epic changes from oe_starter_content.
escuriola Jun 30, 2022
3693a7b
OEL-1552: Update Person view display modes for teaser, full and conte…
escuriola Jun 30, 2022
3dca9f3
OEL-1552: Theming person for full view.
escuriola Jun 30, 2022
afc522c
OEL-1552: Theming person for teaser view.
escuriola Jun 30, 2022
68c72a7
OEL-1552: Add view modes in the install section of the module file info.
escuriola Jun 30, 2022
020afb3
OEL-1552: Prepare the social media links to be rendered.
escuriola Jun 30, 2022
e5928dc
OEL-1552: Templates for document reference and document reference group.
escuriola Jun 30, 2022
6aee466
OEL-1552: Whitelabel person testing.
escuriola Jun 30, 2022
24d8e35
OEL-1552: Fix docblock information.
escuriola Jun 30, 2022
a4a2afa
OEL-1552: Remove extra line.
escuriola Jul 1, 2022
057606a
OEL-1552: Fix person node preprocess because social links may not be …
escuriola Jul 1, 2022
1a20be1
OEL-1552: Sort position correctly. Fix div containers closed at bad p…
escuriola Jul 1, 2022
9cb71cd
OEL-1552: Only display additional info and documents titles if they a…
escuriola Jul 1, 2022
06e6da7
OEL-1552: Renaming template.
escuriola Jul 1, 2022
1456804
OEL-1552: Testing required fields. Improve tests.
escuriola Jul 1, 2022
87ad166
OEL-1552: Use field api in template empty check.
drishu Jul 2, 2022
c17bf97
OEL-1552: Use branch instead of patch for oe_content.
drishu Jul 2, 2022
5714491
OEL-1552: Split the preprocess in view displays.
escuriola Jul 7, 2022
a0a6c14
OEL-1522: Theming teaser and content type. Improve meta array. Inline…
escuriola Jul 7, 2022
6f89136
OEL-1522: Improve theme naming for document group. Theming following …
escuriola Jul 7, 2022
3378b3c
OEL-1522: Hide labels from display. Hide first name and last name fie…
escuriola Jul 7, 2022
3b3e96e
OEL-1522: Improve testing asserts, removing very general filters and …
escuriola Jul 7, 2022
aa67fb7
OEL-1552: Create field templates for additional information and docum…
escuriola Jul 11, 2022
e7805c5
OEL-1552: Remove ps-4 class to document group template.
escuriola Jul 11, 2022
5109695
OEL-1552: Rename person test class.
escuriola Jul 11, 2022
6764448
OEL-1552: Remove empty README file.
escuriola Jul 11, 2022
08934f0
OEL-1552: Remove duplicate and unused code to generate social media l…
escuriola Jul 11, 2022
674b48e
OEL-1552: Remove image from display because is rendered in the prepro…
escuriola Jul 11, 2022
5df5bb0
OEL-1552: Restore call to createExamplePersonWithRequiredFieldsOnly w…
escuriola Jul 12, 2022
f647d03
OEL-1552: Hide social media field from display because is preprocessed.
escuriola Jul 13, 2022
9982874
OEL-1552: Improve docblock. Remove left-overed double quote.
escuriola Jul 13, 2022
4367307
OEL-1552: Remove field_value filter from oe_summary. Check social lin…
escuriola Jul 13, 2022
e276db7
OEL-1552: Improve docblock. Remove social_links variable array initia…
escuriola Jul 13, 2022
5ddd4a2
OEL-1552: Add more document test coverage.
escuriola Jul 13, 2022
a63fe2a
OEL-1552: Docblock indicate the parts of the template name more expli…
escuriola Jul 14, 2022
65df3ca
OEL-1552: Minor changes in test file. Moving closing array and functi…
escuriola Jul 15, 2022
c6f816a
OEL-1552: Moving the empty condition outside the wrapper div.
escuriola Jul 15, 2022
a82a6d4
OEL-1552: Fix typo in docblock and improve comment in docblock.
escuriola Jul 15, 2022
6afe15e
OEL-1552: Use oe_starter_content branch to pull in composer changes.
drishu Jul 25, 2022
566f8d0
OEL-1552: Use oe_starter_content dev.
drishu Jul 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {
drishu marked this conversation as resolved.
Show resolved Hide resolved
"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);
Comment on lines +63 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(tbd, don't implement directly)

Now we call this 3x, before each return.
We are not adding anything else to the $cacheability, so we could do it just once and avoid code repetition.

Suggested change
if (!$access->isAllowed()) {
$cacheability->applyTo($variables);
$cacheability->applyTo($variables);
if (!$access->isAllowed()) {

and then remove the other calls below.

Of course this only works if we don't add anything else to the $cacheability later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to change this back once we introduce image styles.
So maybe keep it for now? @drishu

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any news here @drishu @donquixote

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it for next reviewer.

Copy link
Contributor

@drishu drishu Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed @donquixote, we need to code for what we have, and lets also remove the empty line 70

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but IMHO, this is not a blocker for this task, we have more or less the same in all the CT, so we should create a new ticket and do the fix everywhere and not block this ticket anymore, it's a ticket with a high priority to do this improvement now.

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);
brummbar marked this conversation as resolved.
Show resolved Hide resolved
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();
drishu marked this conversation as resolved.
Show resolved Hide resolved

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
*/
#}
donquixote marked this conversation as resolved.
Show resolved Hide resolved
{% 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 @@
{#
drishu marked this conversation as resolved.
Show resolved Hide resolved
/**
* @file
* Field template of the oe_document_reference for the oe_document document.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still awkward, but I don't have a good counter proposal.
Let's keep it, unless @drishu has a better idea during second review.
(see also the other field templates)

Copy link
Contributor

@drishu drishu Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My proposal is less scientific but more humane and understandable
"Field template of the Document reference entity."
We use the label not machine name this way we can understand.

But @donquixote has to agree first, if not we leave as is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this was Carlos first version, just in lowercase.
My initial request here was to include the field name, bundle and entity type, so we describe what we target.
But it is hard to put that into a single line.

One option would be to put these explanations in a separate block below:

Suggested change
* Field template of the oe_document_reference for the oe_document document.
* Template for the 'Document' field in the 'Document reference' entity type.
*
* Entity type: 'oe_document_reference'.
* Field: 'oe_document'.
* Bundle: 'oe_document'.

Another option is to keep the comment simple and not have it include all the info, and instead we expect the reader to check the template name.
Tbh, I would not trust the comment anyway.

But, here, we actually can squeeze it into one line!

Suggested change
* Field template of the oe_document_reference for the oe_document document.
* Template for the 'Document' field in the 'Document' document reference type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

*
* @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