|
|
|
@ -148,9 +148,31 @@ function ill_corporate_forms_node_presave(\Drupal\node\NodeInterface $node): voi |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Presave logic for ill_institution_request nodes. |
|
|
|
* 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 { |
|
|
|
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; |
|
|
|
$partner_nid = $node->get('field_ill_partner_organization')->target_id; |
|
|
|
if ($partner_nid) { |
|
|
|
if ($partner_nid) { |
|
|
|
$partner_node = \Drupal::entityTypeManager()->getStorage('node')->load($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'); |
|
|
|
$node->setTitle('ILL Request'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|