From aab502a6b9c41a6eafcfdfc045a1e7c3d1f70d57 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes <“joshua.1234511@yahoo.in”> Date: Wed, 2 Oct 2024 08:22:14 +0530 Subject: [PATCH 1/2] [3460512] Added ellipsis to truncated card summary. --- .../contrib/civictheme/includes/paragraphs.inc | 17 +++++++++++++++-- .../contrib/civictheme/includes/utilities.inc | 4 +++- .../civictheme/src/CivicthemeConstants.php | 5 +++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/web/themes/contrib/civictheme/includes/paragraphs.inc b/web/themes/contrib/civictheme/includes/paragraphs.inc index c08f441d8..96975bd30 100644 --- a/web/themes/contrib/civictheme/includes/paragraphs.inc +++ b/web/themes/contrib/civictheme/includes/paragraphs.inc @@ -13,6 +13,7 @@ declare(strict_types=1); use Drupal\civictheme\CivicthemeConstants; +use Drupal\Component\Utility\Unicode; /** * Pre-process for With background paragraph field. @@ -221,7 +222,13 @@ 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; } } @@ -240,7 +247,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; } } } diff --git a/web/themes/contrib/civictheme/includes/utilities.inc b/web/themes/contrib/civictheme/includes/utilities.inc index f1b40965f..5e527f70e 100644 --- a/web/themes/contrib/civictheme/includes/utilities.inc +++ b/web/themes/contrib/civictheme/includes/utilities.inc @@ -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; } diff --git a/web/themes/contrib/civictheme/src/CivicthemeConstants.php b/web/themes/contrib/civictheme/src/CivicthemeConstants.php index 68c1ba28d..72488337e 100644 --- a/web/themes/contrib/civictheme/src/CivicthemeConstants.php +++ b/web/themes/contrib/civictheme/src/CivicthemeConstants.php @@ -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'; + } From 7178bc281eea9e2baa0c31e7111f88746bb7a8ce Mon Sep 17 00:00:00 2001 From: Joshua Fernandes <“joshua.1234511@yahoo.in”> Date: Wed, 2 Oct 2024 08:28:06 +0530 Subject: [PATCH 2/2] Added @SuppressWarnings(PHPMD.StaticAccess) --- web/themes/contrib/civictheme/includes/paragraphs.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/themes/contrib/civictheme/includes/paragraphs.inc b/web/themes/contrib/civictheme/includes/paragraphs.inc index 96975bd30..349f08740 100644 --- a/web/themes/contrib/civictheme/includes/paragraphs.inc +++ b/web/themes/contrib/civictheme/includes/paragraphs.inc @@ -211,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); @@ -234,6 +236,8 @@ function _civictheme_preprocess_paragraph__paragraph_field__summary(array &$vari /** * 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);