Skip to content

Commit

Permalink
Issue #3460512 by joshua1234511, richardgaunt, fionamorrison23, alexs…
Browse files Browse the repository at this point in the history
…krypnyk, alancole: Add ellipsis to truncated card summary. (#1307)

Co-authored-by: Joshua Fernandes <“[email protected]”>
  • Loading branch information
joshua-salsadigital and Joshua Fernandes authored Oct 2, 2024
1 parent ccff5e2 commit 4723b06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
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';

}

0 comments on commit 4723b06

Please sign in to comment.