You are here

protected function MenuTreeResource::removeKeys in REST Menu Tree 8

Same name and namespace in other branches
  1. 2.x src/Plugin/rest/resource/MenuTreeResource.php \Drupal\rest_menu_tree\Plugin\rest\resource\MenuTreeResource::removeKeys()

Remove array keys.

Javascript will re-sort the array based on the key. To prevent this, we'll remove the array keys.

1 call to MenuTreeResource::removeKeys()
MenuTreeResource::get in src/Plugin/rest/resource/MenuTreeResource.php

File

src/Plugin/rest/resource/MenuTreeResource.php, line 123

Class

MenuTreeResource
Provides a resource to get view modes by entity and bundle.

Namespace

Drupal\rest_menu_tree\Plugin\rest\resource

Code

protected function removeKeys(array &$data) {
  $tree = [];
  foreach ($data as $value) {
    if ($value->subtree) {
      $this
        ->removeKeys($value->subtree);
    }
    $tree[] = $value;
  }
  $data = $tree;
}