You are here

public function DemoNode::scrambleData in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::scrambleData()
  2. 8.7 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::scrambleData()
  3. 8.8 modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::scrambleData()
  4. 10.0.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::scrambleData()
  5. 10.1.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::scrambleData()
  6. 10.2.x modules/custom/social_demo/src/DemoNode.php \Drupal\social_demo\DemoNode::scrambleData()

Scramble it.

Parameters

array $data: The data array to scramble.

int|null $max: How many items to generate.

Overrides DemoContent::scrambleData

1 call to DemoNode::scrambleData()
DemoNode::createContent in modules/custom/social_demo/src/DemoNode.php
Creates content.

File

modules/custom/social_demo/src/DemoNode.php, line 241

Class

DemoNode
Class DemoNode.

Namespace

Drupal\social_demo

Code

public function scrambleData(array $data, $max = NULL) {
  $new_data = [];
  for ($i = 0; $i < $max; $i++) {

    // Get a random item from the array.
    $old_uuid = array_rand($data);
    $item = $data[$old_uuid];
    $uuid = 'ScrambledDemo_' . time() . '_' . $i;
    $item['uuid'] = $uuid;
    $item['title'] = $uuid;
    $item['body'] = $uuid;
    $item['created'] = '-' . random_int(1, 2 * 365) . ' day|' . random_int(0, 23) . ':' . random_int(0, 59);
    $new_data[$uuid] = $item;
  }
  return $new_data;
}