/** * Ajax callback to fetch the supported translator services and rebuild the * target / source language dropdowns. */ public function ajaxLanguageSelect(array $form, FormStateInterface $form_state) { $number_of_existing_items = count($this->entity->getConflictingItemIds()); $replace = $form_state->getUserInput()['_triggering_element_name'] == 'source_language' ? 'target_language' : 'source_language'; $response = new AjaxResponse(); $response->addCommand(new ReplaceCommand('#tmgmt-ui-translator-wrapper', $form['translator_wrapper'])); $response->addCommand(new ReplaceCommand('#tmgmt-ui-' . str_replace('_', '-', $replace), $form['info'][$replace])); if ($number_of_existing_items) { $response->addCommand(new InvokeCommand('.existing-items', 'removeClass', array('hidden'))); $response->addCommand(new ReplaceCommand('.existing-items > div', \Drupal::translation()->formatPlural($number_of_existing_items, '1 item conflict with pending item and will be dropped on submission.', '@count items conflict with pending items and will be dropped on submission.'))); } else { $response->addCommand(new InvokeCommand('.existing-items', 'addClass', array('hidden'))); } return $response; }