You are here

public function ParagraphsFrontendUIController::down in Paragraphs frontend ui 8

Same name and namespace in other branches
  1. 8.2 src/Controller/ParagraphsFrontendUIController.php \Drupal\paragraphs_frontend_ui\Controller\ParagraphsFrontendUIController::down()

Shift down a single paragraph.

1 string reference to 'ParagraphsFrontendUIController::down'
paragraphs_frontend_ui.routing.yml in ./paragraphs_frontend_ui.routing.yml
paragraphs_frontend_ui.routing.yml

File

src/Controller/ParagraphsFrontendUIController.php, line 45

Class

ParagraphsFrontendUIController
Controller for up and down actions.

Namespace

Drupal\paragraphs_frontend_ui\Controller

Code

public function down($paragraph, $js = 'nojs') {
  $paragraph = $paragraph
    ->getTranslation($this
    ->langcode());
  extract($this
    ->getParentData($paragraph));
  $paragraph_items = $parent->{$parent_field_name}
    ->getValue();
  $numitems = count($paragraph_items);
  foreach ($paragraph_items as $delta => $paragraph_item) {
    if ($paragraph_item['target_id'] == $paragraph
      ->id()) {
      if ($delta < $numitems) {
        $next_paragraph = $paragraph_items[$delta + 1];
        $paragraph_items[$delta + 1] = $paragraph_items[$delta];
        $paragraph_items[$delta] = $next_paragraph;
      }
      break;
    }
  }
  $parent->{$parent_field_name}
    ->setValue($paragraph_items);
  $parent
    ->save();
  return $this
    ->refreshWithAJaxResponse($parent, $parent_field_name);
}