From cf1993f69204c31e69c32ba03cbbd41fdad1fa7c Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Fri, 27 Feb 2026 11:39:10 -0400 Subject: [PATCH] altered the hook form alter for custom title on a request --- ill_corporate_forms.module | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ill_corporate_forms.module b/ill_corporate_forms.module index 7ca68b2..241a78a 100644 --- a/ill_corporate_forms.module +++ b/ill_corporate_forms.module @@ -148,9 +148,31 @@ function ill_corporate_forms_node_presave(\Drupal\node\NodeInterface $node): voi /** * Presave logic for ill_institution_request nodes. * - * Sets the title to the Borrowing Library name. + * Builds the title from Item Title, Journal Title, and Article Title fields + * (separated by " - "). Falls back to the Borrowing Library name if none of + * those fields are populated. */ function _ill_corporate_forms_presave_request(\Drupal\node\NodeInterface $node): void { + // Build title from the item/journal/article title fields. + $title_parts = []; + foreach (['field_ill_item_title', 'field_ill_journal_title', 'field_ill_article_title'] as $field_name) { + $value = $node->get($field_name)->value; + if (!empty($value)) { + $title_parts[] = trim($value); + } + } + + if (!empty($title_parts)) { + $title = implode(' - ', $title_parts); + // Drupal node title max length is 255 characters. + if (mb_strlen($title) > 255) { + $title = mb_substr($title, 0, 252) . '...'; + } + $node->setTitle($title); + return; + } + + // Fallback: use the Borrowing Library name. $partner_nid = $node->get('field_ill_partner_organization')->target_id; if ($partner_nid) { $partner_node = \Drupal::entityTypeManager()->getStorage('node')->load($partner_nid); @@ -160,7 +182,6 @@ function _ill_corporate_forms_presave_request(\Drupal\node\NodeInterface $node): } } - // Fallback if no borrowing library is set. $node->setTitle('ILL Request'); }