You are here

protected function AcquiadamServiceTest::getFolderData in Media: Acquia DAM 8

Get the specific folder from an array of folders.

Parameters

int $folderId: The ID of the folder to retrieve.

array $folders: The array of folders to look for. Defaults to getTopLevelFoldersData().

Return value

object|null The folder if found, NULL otherwise.

2 calls to AcquiadamServiceTest::getFolderData()
AcquiadamServiceTest::setUp in tests/src/Unit/AcquiadamServiceTest.php
AcquiadamServiceTest::testSelfGetFolderData in tests/src/Unit/AcquiadamServiceTest.php
Validate our helper method for testing folder data works as expected.

File

tests/src/Unit/AcquiadamServiceTest.php, line 162

Class

AcquiadamServiceTest
Acquia DAM REST extension tests.

Namespace

Drupal\Tests\media_acquiadam\Unit

Code

protected function getFolderData($folderId, array $folders = []) {
  if (empty($folders)) {
    $folders = $this
      ->getTopLevelFoldersData();
  }
  foreach ($folders as $folder) {
    if (!empty($folder->id) && $folder->id == $folderId) {
      return $folder;
    }
    elseif (!empty($folder->folders)) {
      $child = $this
        ->getFolderData($folderId, $folder->folders);
      if (!empty($child)) {
        return $child;
      }
    }
  }
  return NULL;
}