You are here

protected function JobForm::getConflictingItemsMessage in Translation Management Tool 8

Builds a message on conflicting job items.

Parameters

\Drupal\tmgmt\JobInterface $job: The job to build the message for.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup|null Either a message with the inforamtion about the conflicting items or null if there are none.

2 calls to JobForm::getConflictingItemsMessage()
JobForm::ajaxLanguageSelect in src/Form/JobForm.php
Ajax callback to fetch the supported translator services and rebuild the target / source language dropdowns.
JobForm::form in src/Form/JobForm.php
Gets the actual form array to be built.

File

src/Form/JobForm.php, line 881

Class

JobForm
Form controller for the job edit forms.

Namespace

Drupal\tmgmt\Form

Code

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,
  ]);
}