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-1017: [oe_whitelabel] Style the news content type #68

Merged
merged 23 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
054e7b0
OEL-1017: Create OE Whitelabel News submodule and import OE Starter C…
GilNovacomm Feb 10, 2022
88958ee
OEL-1017: Create Full and Teaser display templates for News and prepr…
GilNovacomm Feb 10, 2022
5b03dd4
OEL-1017: Require oe_starter_content as dependency and update php ver…
GilNovacomm Feb 10, 2022
7287bd7
OEL-1017: Create rendering tests for full and teaser displays and upd…
GilNovacomm Feb 10, 2022
231db83
OEL-1017: Use original media instead of an image style when preproces…
GilNovacomm Feb 10, 2022
e54ff09
OEL-1017: OEL-1017: Update minimal versions of file_link, pathauto an…
Feb 10, 2022
692208f
OEL-1017: Update Drupal 9.1 to 9.2. along with its dependencies.
GilNovacomm Feb 11, 2022
2075ee0
OEL-1017: Code standards.
GilNovacomm Feb 11, 2022
b63de56
OEL-1017: Clean pattern variable and code standards.
GilNovacomm Feb 11, 2022
1c1e56b
OEL-1017: Add config dependencies for module.
Feb 15, 2022
ac52df4
OEL-1017: Correct test comments and create test instance node.
GilNovacomm Feb 16, 2022
966f14f
OEL-1017: Add whitelabel helper as a dependency.
GilNovacomm Feb 17, 2022
8f3f0cf
OEL-1017: Correctly name OE News date and update the node displays.
GilNovacomm Feb 17, 2022
dfc5ca4
OEL-1017: Remove unecessary validation.
GilNovacomm Feb 17, 2022
7f6ac39
OEL-1017: Add dateformat.
GilNovacomm Feb 17, 2022
2d04bc4
OEL-1017: Improve template semantics, remove unused variables and gen…
GilNovacomm Feb 17, 2022
5011331
OEL-1017: Rename base test class, remove browser rendering from test …
GilNovacomm Feb 17, 2022
993902f
OEL-1017: Create a template for field oe_publication_date and remove …
GilNovacomm Feb 17, 2022
349724b
OEL-1017: Use composer v1 until support for 2 is complete in OpenEuropa.
GilNovacomm Feb 17, 2022
7ecbfe1
OEL-1017: Set content variable using markup on teaser template and up…
GilNovacomm Feb 17, 2022
e8f1771
OEL-1017: Code standards.
GilNovacomm Feb 17, 2022
c24dc68
OEL-1017: Downgrade compose on lowest installation for drone.
GilNovacomm Feb 17, 2022
3fc38c6
OEL-1017: Set variable as protected.
GilNovacomm Feb 18, 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
4 changes: 3 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pipeline:
volumes:
- /cache:/cache
commands:
- composer self-update --1
- composer install --ansi --no-suggest --no-progress

composer-update-lowest:
Expand All @@ -51,6 +52,7 @@ pipeline:
volumes:
- /cache:/cache
commands:
- composer self-update --1
- composer update --prefer-lowest --ansi --no-suggest --no-progress
when:
event:
Expand Down Expand Up @@ -105,4 +107,4 @@ matrix:
- lowest
- highest
PHP_VERSION:
- 7.3
- 7.4
35 changes: 25 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.3",
"php": ">=7.4",
"cweagans/composer-patches": "^1.7",
"drupal/core": "^8.9 || ^9.1",
"drupal/core": "^8.9 || ^9.2",
"openeuropa/oe_bootstrap_theme": "0.1.202202072010"
},
"require-dev": {
"composer/installers": "^1.11",
"drupal/core-composer-scaffold": "^8.9 || ^9.1",
"drupal/config_devel": "~1.2",
"drupal/better_exposed_filters": "^5.0",
"drupal/config_devel": "~1.2",
"drupal/core-composer-scaffold": "^8.9 || ^9.2",
"drupal/ctools": "^3.7",
"drupal/drupal-extension": "~4.1",
"drupal/file_link": "^2.0.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

why is needed?

  • file_link, pathauto, email_validator?

Copy link
Contributor Author

@GilNovacomm GilNovacomm Feb 11, 2022

Choose a reason for hiding this comment

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

This issue is due to when installing the lowest versions:
Downgrading drupal/core (9.2.12 => 9.2.0): Loading from cache
these modules do not have the core_version_requirement key on their info file.
An explanation to each is on the _readme key on composer.json
"_readme": [ "Explicit minimum version requirement of drupal/ctools module due to D9.2 compatability.", "Explicit requirement for drupal/file_link due to https://www.drupal.org/project/file_link/issues/3147517. It can be removed when oe_media requires version 2.0.4 or above.", "Explicit requirement for drupal/pathauto due to D9.2 compatability according to https://www.drupal.org/node/2979476.", "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." ],

"drupal/pathauto": "^1.8",
"drupal/search_api": "^1.21",
"drupal/search_api_autocomplete": "^1.5",
"drush/drush": "^10.3",
"openeuropa/code-review": "1.7",
"easyrdf/easyrdf": "1.0.0 as 0.9.1",
"egulias/email-validator": "^2.1.22 || ^3.0",
"openeuropa/code-review": "^1.7 || ^2.0",
"openeuropa/composer-artifacts": "~0.1",
"openeuropa/drupal-core-require-dev": "^8.9 || ^9.1",
"openeuropa/drupal-core-require-dev": "^8.9 || ^9.2",
"openeuropa/oe_authentication": "^1.4",
"openeuropa/oe_corporate_blocks": "^4.4",
"openeuropa/oe_multilingual": "^1.9",
"openeuropa/oe_starter_content": "1.x-dev",
"openeuropa/task-runner-drupal-project-symlink": "^1.0",
"phpspec/prophecy-phpunit": "^1 || ^2",
"easyrdf/easyrdf": "1.0.0 as 0.9.1",
"drupal/search_api": "^1.21",
"drupal/search_api_autocomplete": "^1.5"
"phpspec/prophecy-phpunit": "^1 || ^2"
},
"scripts": {
"post-install-cmd": "./vendor/bin/run drupal:site-setup",
Expand All @@ -38,6 +43,10 @@
"drupal":{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"openeuropa/oe_starter_content": {
"type": "git",
"url": "https://github.com/openeuropa/oe_starter_content"
}
},
"extra": {
Expand All @@ -56,6 +65,12 @@
"web-root": "./build"
}
},
"_readme": [
"Explicit minimum version requirement of drupal/ctools module due to D9.2 compatability.",
"Explicit requirement for drupal/file_link due to https://www.drupal.org/project/file_link/issues/3147517. It can be removed when oe_media requires version 2.0.4 or above.",
"Explicit requirement for drupal/pathauto due to D9.2 compatability according to https://www.drupal.org/node/2979476.",
"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."
],
"installer-paths": {
"build/core": [
"type:drupal-core"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '2'
services:
web:
image: fpfis/httpd-php-dev:7.3
image: fpfis/httpd-php-dev:7.4
working_dir: /var/www/html
ports:
- 8080:8080
Expand Down
1 change: 1 addition & 0 deletions modules/oe_whitelabel_news/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# OpenEuropa Whitelabel News
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: oe_whitelabel_news_date
label: 'OE Whitelabel News date'
locked: false
pattern: 'd F Y'
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.oe_news.body
- field.field.node.oe_news.oe_featured_media
- field.field.node.oe_news.oe_publication_date
- field.field.node.oe_news.oe_summary
- node.type.oe_news
module:
- datetime
- text
- user

id: node.oe_news.full
targetEntityType: node
bundle: oe_news
mode: full
content:
body:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 12
region: content
links:
settings: { }
third_party_settings: { }
weight: 100
region: content
oe_featured_media:
type: entity_reference_entity_view
label: hidden
settings:
view_mode: default
link: false
third_party_settings: { }
weight: 10
region: content
oe_publication_date:
type: datetime_default
label: hidden
settings:
timezone_override: ''
format_type: oe_whitelabel_news_date
third_party_settings: { }
weight: 13
region: content
oe_summary:
type: basic_string
label: hidden
settings: { }
third_party_settings: { }
weight: 11
region: content
hidden:
langcode: true
search_api_excerpt: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.oe_news.body
- field.field.node.oe_news.oe_featured_media
- field.field.node.oe_news.oe_publication_date
- field.field.node.oe_news.oe_summary
- node.type.oe_news
module:
- datetime
- text
- user

id: node.oe_news.teaser
targetEntityType: node
bundle: oe_news
mode: teaser
content:
body:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 12
region: content
links:
settings: { }
third_party_settings: { }
weight: 100
region: content
oe_featured_media:
type: entity_reference_entity_view
label: hidden
settings:
view_mode: default
link: false
third_party_settings: { }
weight: 10
region: content
oe_publication_date:
type: datetime_default
label: hidden
settings:
timezone_override: ''
format_type: oe_whitelabel_news_date
third_party_settings: { }
weight: 13
region: content
oe_summary:
type: basic_string
label: hidden
settings: { }
third_party_settings: { }
weight: 11
region: content
hidden:
langcode: true
search_api_excerpt: true
14 changes: 14 additions & 0 deletions modules/oe_whitelabel_news/oe_whitelabel_news.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: OpenEuropa Whitelabel News
type: module
description: Companion module to OE News providing styling to nodes.
package: OpenEuropa Whitelabel Theme
core_version_requirement: ^8.9 || ^9.2
dependencies:
- oe_whitelabel:oe_whitelabel_helper
- oe_starter_content:oe_starter_content_news
brummbar marked this conversation as resolved.
Show resolved Hide resolved

config_devel:
install:
- core.date_format.oel_whitelabel_news_date.yml
- core.entity_view_display.node.oe_news.full.yml
- core.entity_view_display.node.oe_news.teaser.yml
76 changes: 76 additions & 0 deletions modules/oe_whitelabel_news/oe_whitelabel_news.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

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

declare(strict_types = 1);

use Drupal\Core\Cache\CacheableMetadata;
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 template_preprocess_node() for the News node type.
*/
function oe_whitelabel_news_preprocess_node__oe_news(&$variables) {
if ($variables['view_mode'] !== 'full' && $variables['view_mode'] !== 'teaser') {
return;
}

/** @var \Drupal\node\NodeInterface $node */
$node = $variables['node'];

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

/** @var \Drupal\media\Entity\Media $media */
$media = $node->get('oe_featured_media')->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());

// Caches are handled by the formatter usually. Since we are not rendering
// the original render arrays, we need to propagate our caches to the
// paragraph template.
$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 and not a video, bail out.
if (!$is_image) {
$cacheability->applyTo($variables);
return;
}

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

if ($variables['view_mode'] == 'teaser') {
$variables['image'] = ['#markup' => $variables['image']->getSource()];
}

$cacheability->applyTo($variables);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{#
/**
* @file
* Theme override for field oe-publication-date.
*/
#}
{% if label_hidden %}
{% for item in items %}
{{ item.content }}
{% endfor %}
{% else %}
{{ label }}
{% for item in items %}
{{ item.content }}
{% endfor %}
{% endif %}
25 changes: 25 additions & 0 deletions modules/oe_whitelabel_news/templates/node--oe-news--full.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{#
/**
* @file
* News full display.
*/
#}
<article{{attributes}}>
{{ pattern('content_banner', {
background: 'gray',
title: label,
content: content.oe_summary,
image: image,
meta: [
content.oe_publication_date,
]
}) }}

<div class="container mt-md-4-75 mt-4">
<div class="row">
<div class="col-12 col-lg-10 col-xl-9 col-xxl-8 mb-4">
{{ content.body }}
</div>
</div>
</div>
</article>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{#
/**
* @file
* Search result template.
*/
#}
{% set _title %}
<a class="text-underline-hover" href="{{ url }}">{{ label }}</a>
{% endset %}
{% set _content %}
<span class="text-muted text-nowrap me-4-5">{{ content.oe_publication_date }}</span>
{% endset %}
<article{{attributes}}>
{{ pattern('card', {
variant: 'search',
title: _title,
text: content.oe_summary,
image: image,
content: _content
}) }}
</article>
Loading