<?php

/**
 * @file
 * Initialization of content for d_product module.
 */

/**
 * Alter content structure.
 *
 * Implements hook_content_structure_alter()
 *
 * @param array $structure
 *   The array with structure.
 * @param string $context
 *   Which structure array is this?
 */
function d_product_init_content_structure_alter(array &$structure, $context) {
  $path = \Drupal::service('extension.path.resolver')->getPath('module', 'd_product_init') . '/pages';

  if ($context == 'all') {
    $products = [];
    // Make product_1 as first on product list by decrement loop.
    for ($i = 5; $i >= 1; $i--) {
      $products['product_' . $i] = [
        'file' => "$path/product_{$i}.yml",
        'weight' => 0,
      ];
    }
    $structure = $products + $structure;
  }
}

/**
 * Implements hook_d_content_init_index_content().
 */
function d_product_init_d_content_init_index_content(array &$indexes) {
  $indexes[] = 'product_index';
}
