You are here

public function DemoContent::scrambleData in Open Social 8.9

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

Scramble it.

Parameters

array $data: The data array to scramble.

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

Overrides DemoContentInterface::scrambleData

5 calls to DemoContent::scrambleData()
DemoComment::createContent in modules/custom/social_demo/src/DemoComment.php
Creates content.
DemoEntity::createContent in modules/custom/social_demo/src/DemoEntity.php
Creates content.
DemoGroup::createContent in modules/custom/social_demo/src/DemoGroup.php
Creates content.
DemoSystem::createContent in modules/custom/social_demo/src/DemoSystem.php
Creates content.
DemoTaxonomyTerm::createContent in modules/custom/social_demo/src/DemoTaxonomyTerm.php
Creates content.
2 methods override DemoContent::scrambleData()
DemoNode::scrambleData in modules/custom/social_demo/src/DemoNode.php
Scramble it.
DemoUser::scrambleData in modules/custom/social_demo/src/DemoUser.php
Scramble it.

File

modules/custom/social_demo/src/DemoContent.php, line 291

Class

DemoContent
Class DemoContent.

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;
    $new_data[$uuid] = $item;
  }
  return $new_data;
}