You are here

public function GeysirCutPasteController::cut in Geysir 8

Cut a paragraph entity.

1 string reference to 'GeysirCutPasteController::cut'
geysir.routing.yml in ./geysir.routing.yml
geysir.routing.yml

File

src/Controller/GeysirCutPasteController.php, line 17

Class

GeysirCutPasteController
Controller for cut & paste functionality.

Namespace

Drupal\geysir\Controller

Code

public function cut($parent_entity_type, $parent_entity_bundle, $parent_entity_revision, $field, $field_wrapper_id, $delta, $paragraph_to_cut, $paragraph_revision, $js = 'nojs') {
  if ($js == 'ajax') {

    // Get the parent revision if available, otherwise the parent.
    $parent_entity_revision = $this
      ->getParentRevisionOrParent($parent_entity_type, $parent_entity_revision);
    $parent_entity_revision
      ->get($field)
      ->removeItem($delta);
    $response = new AjaxResponse();
    $response
      ->addCommand(new ReplaceCommand(sprintf('[data-geysir-field-paragraph-field-wrapper="%s"]', $field_wrapper_id), $parent_entity_revision
      ->get($field)
      ->view('default')));
    return $response;
  }
  return $this
    ->t('Javascript is required for this functionality to work properly.');
}