You are here

public function AllDocsNormalizer::normalize in Replication 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/AllDocsNormalizer.php \Drupal\replication\Normalizer\AllDocsNormalizer::normalize()

File

src/Normalizer/AllDocsNormalizer.php, line 14

Class

AllDocsNormalizer

Namespace

Drupal\replication\Normalizer

Code

public function normalize($all_docs, $format = NULL, array $context = []) {
  $data = [
    'offset' => 0,
    'rows' => [],
  ];

  /** @var \Drupal\replication\AllDocs\AllDocsInterface $all_docs */
  if (!empty($context['query']['include_docs'])) {
    $all_docs
      ->includeDocs(TRUE);
  }
  $rows = $all_docs
    ->execute();
  foreach ($rows as $key => $value) {
    $data['rows'][] = [
      'id' => $key,
      'key' => $key,
      'value' => $value,
    ];
  }
  $data['total_rows'] = count($rows);
  return $data;
}