You are here

function realistic_dummy_content_api_improve_dummy_content in Realistic Dummy Content 8.2

Same name and namespace in other branches
  1. 8 api/realistic_dummy_content_api.module \realistic_dummy_content_api_improve_dummy_content()
  2. 7.2 api/realistic_dummy_content_api.module \realistic_dummy_content_api_improve_dummy_content()
  3. 7 api/realistic_dummy_content_api.module \realistic_dummy_content_api_improve_dummy_content()
  4. 3.x api/realistic_dummy_content_api.module \realistic_dummy_content_api_improve_dummy_content()

Insert or improve dummy data in an entity of a given type.

Parameters

object $entity: The object for a given type, for example this can be a user object or a node object.

string $type: The type of the information to change, for example 'user' or 'node'.

array $filter: (Default is array()). If set, only certain fields will be considered when manipulating the object. This can be useful, for example for users, because two separate manipulations need to be performed, depending on whether hook_user_insert() or hook_user_presave(). Both hooks need to modify only certain properties and fields, but taken together the entire object can be manipulated. The filter is an associative array which can contain no key (all fields and properties should be manipulated), the include key (fields included are the only ones to be manipulated, or the exclude key (all fields except those included are the ones to be manipulated).

realistic_dummy_content_api_user_insert() defines the array ('exclude' => array(picture)) whereas realistic_dummy_content_api_user_presave() defines the array ('include' => array(picture)). Therefore taken together these two hooks manipulate the entire user object, but in two phases.

This allows hook implementations to return a different class based on the type of filter.

Throws

\Exception

3 calls to realistic_dummy_content_api_improve_dummy_content()
Drupal7::genericEntityPresave in api/src/Framework/Drupal7.php
Generic function called by various hooks in Drupal.
Drupal8::hookEntityPresave in api/src/Framework/Drupal8.php
Mock::hookEntityPresave in api/src/Framework/Mock.php

File

api/realistic_dummy_content_api.module, line 263
API code allowing other modules to generate realistic dummy content.

Code

function realistic_dummy_content_api_improve_dummy_content(&$entity, $type, $filter = array()) {
  realistic_dummy_content_api_argcheck(array(
    'is_object',
    'realistic_dummy_content_api_argcheck_entitytype',
  ));
  $modifiers = Framework::instance()
    ->moduleInvokeAll('realistic_dummy_content_api_class', $entity, $type, $filter);
  $candidate = $entity;
  foreach ($modifiers as $modifier_class) {
    realistic_dummy_content_api_validate_class($modifier_class);
    $modifier = new $modifier_class($candidate, $type, $filter);
    $modifier
      ->modify();
    $candidate = $modifier
      ->getEntity();
  }
  $entity = $candidate;
}