Builds a message on conflicting job items.
\Drupal\tmgmt\JobInterface $job: The job to build the message for.
\Drupal\Core\StringTranslation\TranslatableMarkup|null Either a message with the inforamtion about the conflicting items or null if there are none.
protected function getConflictingItemsMessage(JobInterface $job) : ?TranslatableMarkup {
// Checkout whether given source already has items in translation.
$conflicting_items_by_item = $job
->getConflictingItems();
if (!$conflicting_items_by_item) {
return NULL;
}
// Make a list of links to the existing items causing the conflicts.
$conflicts = [];
$num_of_existing_items = 0;
foreach ($conflicting_items_by_item as $conflicting_items) {
$num_of_existing_items += count($conflicting_items);
foreach (JobItem::loadMultiple($conflicting_items) as $id => $conflicting_item) {
$conflicts[] = Link::createFromRoute($conflicting_item
->label(), 'entity.tmgmt_job_item.canonical', [
'tmgmt_job_item' => $id,
])
->toString();
}
}
// Make the links usable in formatPlural().
$conflict_list = Markup::create(implode(', ', $conflicts));
return \Drupal::translation()
->formatPlural($num_of_existing_items, '1 item conflicts with pending item and will be dropped on submission. Conflicting item: @items.', '@count items conflict with pending items and will be dropped on submission. Conflicting items: @items.', [
'@items' => $conflict_list,
]);
}