You are here

public function GeysirModalController::translate in Geysir 8

Create a modal dialog to translate a single paragraph.

1 string reference to 'GeysirModalController::translate'
geysir.routing.yml in ./geysir.routing.yml
geysir.routing.yml

File

src/Controller/GeysirModalController.php, line 132

Class

GeysirModalController
Controller for all modal dialogs.

Namespace

Drupal\geysir\Controller

Code

public function translate($parent_entity_type, $parent_entity_bundle, $parent_entity_revision, $field, $field_wrapper_id, $delta, Paragraph $paragraph, $paragraph_revision, $js = 'nojs') {
  if ($js == 'ajax') {
    $response = new AjaxResponse();
    $langcode = $this
      ->languageManager()
      ->getCurrentLanguage()
      ->getId();
    $translated_paragraph = $paragraph
      ->addTranslation($langcode, $paragraph
      ->toArray());
    $form = $this
      ->entityFormBuilder()
      ->getForm($translated_paragraph, 'geysir_modal_edit', []);
    $paragraph_title = $this
      ->getParagraphTitle($parent_entity_type, $parent_entity_bundle, $field);
    $response
      ->addCommand(new GeysirOpenModalDialogCommand($this
      ->t('Translate @paragraph_title', [
      '@paragraph_title' => $paragraph_title,
    ]), render($form)));
    return $response;
  }
  return $this
    ->t('Javascript is required for this functionality to work properly.');
}