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

Issue #3460512 by joshua1234511, richardgaunt, fionamorrison23, alexskrypnyk, alancole: Add ellipsis to truncated card summary. #1307

Merged
merged 2 commits into from
Oct 2, 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
21 changes: 19 additions & 2 deletions web/themes/contrib/civictheme/includes/paragraphs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
declare(strict_types=1);

use Drupal\civictheme\CivicthemeConstants;
use Drupal\Component\Utility\Unicode;

/**
* Pre-process for With background paragraph field.
Expand Down Expand Up @@ -210,6 +211,8 @@ function _civictheme_preprocess_paragraph__paragraph_field__links(array &$variab

/**
* Pre-process for Summary paragraph field.
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
function _civictheme_preprocess_paragraph__paragraph_field__summary(array &$variables): void {
$summary = civictheme_get_field_value($variables['paragraph'], 'field_c_p_summary', TRUE);
Expand All @@ -221,12 +224,20 @@ function _civictheme_preprocess_paragraph__paragraph_field__summary(array &$vari
$length = civictheme_get_theme_config_manager()->loadForComponent($component_name, 'summary_length', CivicthemeConstants::COMPONENT_SUMMARY_DEFAULT_LENGTH);
}

$variables['summary'] = text_summary($summary, NULL, $length);
$summary_trimmed = text_summary($summary);

if (!_civictheme_feature_is_optedout('process', CivicthemeConstants::OPTOUT_SUMMARY_HIDE_ELLIPSIS)) {
$summary_trimmed = Unicode::truncate($summary_trimmed, $length, TRUE, TRUE);
}

$variables['summary'] = $summary_trimmed;
}
}

/**
* Pre-process for Summary node field.
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
function _civictheme_preprocess_paragraph__node_field__summary(array &$variables, string $bundle = NULL): void {
$node = $variables['node'] ?? civictheme_get_field_value($variables['paragraph'], 'field_c_p_reference', TRUE);
Expand All @@ -240,7 +251,13 @@ function _civictheme_preprocess_paragraph__node_field__summary(array &$variables
$length = civictheme_get_theme_config_manager()->loadForComponent($component_name, 'summary_length', CivicthemeConstants::COMPONENT_SUMMARY_DEFAULT_LENGTH);
}

$variables['summary'] = text_summary($summary, NULL, $length);
$summary_trimmed = text_summary($summary);

if (!_civictheme_feature_is_optedout('process', CivicthemeConstants::OPTOUT_SUMMARY_HIDE_ELLIPSIS)) {
$summary_trimmed = Unicode::truncate($summary_trimmed, $length, TRUE, TRUE);
}

$variables['summary'] = $summary_trimmed;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion web/themes/contrib/civictheme/includes/utilities.inc
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,10 @@ function _civictheme_feature_is_optedout(string $type, string $name, mixed $cont
* Array of opt-out flags.
*/
function _civictheme_feature_optout_flags(): array {
return [
$flags = [
'components.link' => t('Links processing'),
'components.link.email' => t('Email links processing'),
];
$flags[CivicthemeConstants::OPTOUT_SUMMARY_HIDE_ELLIPSIS] = t('Hide card summary ellipsis');
return $flags;
}
5 changes: 5 additions & 0 deletions web/themes/contrib/civictheme/src/CivicthemeConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,9 @@ final class CivicthemeConstants {
*/
const OPTOUT_VIEWS_STYLE_TABLE = 'CivicThemeOptoutViewsStyleTable';

/**
* Defines an optout string for card summary ellipsis.
*/
const OPTOUT_SUMMARY_HIDE_ELLIPSIS = 'CivicThemeOptoutSummaryHideEllipsis';

}
Loading