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

Rw 821 #698

Merged
merged 10 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
uses: cafuego/command-output@main
with:
run: |
docker compose -f tests/docker-compose.yml exec -T drupal drush -y si --existing-config
docker compose -f tests/docker-compose.yml exec -T drupal drush -y si --existing-config minimal install_configure_form.enable_update_status_emails=NULL
env:
fail-fast: true

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 58 additions & 3 deletions html/modules/custom/reliefweb_meta/reliefweb_meta.module
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ function reliefweb_meta_get_node_metatags(NodeInterface $node) {
$description .= reliefweb_meta_description_term_list($node, $terms, ['source' => 1], 'from');
// Closing date.
$description .= reliefweb_meta_description_date($node, 'job_closing_date', '; closing on ');

// Image.
$image = reliefweb_meta_get_image($node);

break;

case 'report':
Expand Down Expand Up @@ -252,7 +256,7 @@ function reliefweb_meta_get_node_metatags(NodeInterface $node) {
}

// Image.
$image = reliefweb_meta_report_image($node);
$image = reliefweb_meta_get_image($node);
break;

// @todo we could use the topic icon but the quality is not always good.
Expand Down Expand Up @@ -317,6 +321,10 @@ function reliefweb_meta_get_node_metatags(NodeInterface $node) {
}
// Registration date.
$description .= reliefweb_meta_description_date($node, 'registration_deadline', '; registration until ');

// Image.
$image = reliefweb_meta_get_image($node);

break;

}
Expand Down Expand Up @@ -382,6 +390,10 @@ function reliefweb_meta_get_term_metatags(TermInterface $term) {
$description = t('Humanitarian situation reports, response plans, news, analyses, evaluations, assessments, maps, infographics and more on @name', [
'@name' => $term->label(),
]);

// Image.
$image = reliefweb_meta_get_image($term);

break;

case 'source':
Expand Down Expand Up @@ -696,15 +708,15 @@ function reliefweb_meta_description_date(FieldableEntityInterface $entity, $fiel
}

/**
* Get metadata image for report pages.
* Get metadata image.
*
* @param \Drupal\Core\Entity\FieldableEntityInterface $entity
* Entity.
*
* @return string
* Url of the report image.
*/
function reliefweb_meta_report_image(FieldableEntityInterface $entity) {
function reliefweb_meta_get_image(FieldableEntityInterface $entity) {
// Headline image.
$image = reliefweb_meta_get_entity_image_url($entity, 'field_headline_image');

Expand All @@ -729,6 +741,21 @@ function reliefweb_meta_report_image(FieldableEntityInterface $entity) {
}
}

// Country icon.
if (empty($image)) {
$iso3 = '';
if ($entity->hasField('field_primary_country') && !$entity->field_primary_country->isEmpty()) {
$iso3 = $entity->field_primary_country->entity?->field_iso3?->value;
}
elseif ($entity->hasField('field_country') && !$entity->field_country->isEmpty()) {
$iso3 = $entity->field_country->entity?->field_iso3?->value;
}

if (!empty($iso3)) {
$image = reliefweb_meta_get_country_icon($iso3);
}
}

// Default to RW logo for social media.
return $image ?: reliefweb_meta_get_image_url();
}
Expand Down Expand Up @@ -759,6 +786,34 @@ function reliefweb_meta_get_entity_shortlink(EntityInterface $entity) {
])->toString();
}

/**
* Get the icon for a given country.
*
* @param string $iso3
* Country ISO3 code.
*
* @return string
* Image URL of icon.
*/
function reliefweb_meta_get_country_icon($iso3) {
$module_path = \Drupal::service('extension.path.resolver')
->getPath('module', 'reliefweb_meta');
$path = $module_path . '/images/icons';

$files = \Drupal::service('file_system')->scanDirectory($path, '/_' . $iso3 . '\.png$/i');
if ($files) {
$file = reset($files);
if ($path && file_exists($path)) {
return Url::fromUserInput('/' . $file->uri, [
'absolute' => TRUE,
'path_processing' => FALSE,
])->toString();
}
}

return '';
}

/**
* Get the URL of an image.
*
Expand Down
Loading