Skip to content

Commit

Permalink
Merge pull request tripal#1949 from tripal/tv4g1-issue1948-null-in-fo…
Browse files Browse the repository at this point in the history
…rmatter

don't add to render array if no value
  • Loading branch information
laceysanderson authored Aug 26, 2024
2 parents 7ef42b4 + 5c4617d commit 3ad2f09
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];

foreach($items as $delta => $item) {
$elements[$delta] = [
"#markup" => $item->get("value")->getValue() ? $true_string : $false_string,
];
$value = $item->get("value")->getValue();
if (!is_null($value) and strlen($value)) {
$elements[$delta] = [
"#markup" => $value ? $true_string : $false_string,
];
}
}

return $elements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ public function viewElements(FieldItemListInterface $items, $langcode) {

foreach($items as $delta => $item) {
$value = $item->get("value")->getValue();
if (strlen($thousand_separator)) {
// For an integer we can hardcode the unused decimal setting
$value = number_format(floatval($value), 0, '.', $thousand_separator);
if (!is_null($value) and strlen($value)) {
if (strlen($thousand_separator)) {
// For an integer we can hardcode the unused decimal setting
$value = number_format(floatval($value), 0, '.', $thousand_separator);
}
$elements[$delta] = [
"#markup" => $field_prefix . $value . $field_suffix,
];
}
$elements[$delta] = [
"#markup" => $field_prefix . $value . $field_suffix,
];
}

return $elements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public function viewElements(FieldItemListInterface $items, $langcode) {

foreach($items as $delta => $item) {
$value = $item->get('value')->getString();
$elements[$delta] = [
"#markup" => $field_prefix . $value . $field_suffix,
];
if (!is_null($value) and strlen($value)) {
$elements[$delta] = [
"#markup" => $field_prefix . $value . $field_suffix,
];
}
}

return $elements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ public function viewElements(FieldItemListInterface $items, $langcode) {

foreach($items as $delta => $item) {
$value_string = $item->get('value')->getValue();
$elements[$delta] = [
'#type' => 'processed_text',
'#text' => $value_string,
'#format' => $filter_format,
'#langcode' => $item->getLangcode(),
];
if (!is_null($value_string) and strlen($value_string)) {
$elements[$delta] = [
'#type' => 'processed_text',
'#text' => $value_string,
'#format' => $filter_format,
'#langcode' => $item->getLangcode(),
];
}
}

return $elements;
Expand Down

0 comments on commit 3ad2f09

Please sign in to comment.