You are here

function _datalayer_collect_meta_values in dataLayer 8

Same name and namespace in other branches
  1. 7 datalayer.module \_datalayer_collect_meta_values()

Add the meta properties for given entity.

Parameters

array $properties: Selected properties for the entity.

\Drupal\Core\Entity\EntityInterface $entity: The entity.

string $key_prefix: The prefix for the property name.

2 calls to _datalayer_collect_meta_values()
datalayer_get_user_data in ./datalayer.module
Return all user data based on configured URL patterns.
_datalayer_get_entity_data in ./datalayer.module
Collect entity data for output and altering.

File

./datalayer.module, line 612
Client-side data space.

Code

function _datalayer_collect_meta_values(array $properties, EntityInterface $entity, $key_prefix = 'entity') {

  // Build meta output...
  $meta_data = [];
  foreach ($properties as $p) {
    if (isset($entity->{$p}) && method_exists($entity->{$p}, 'getString')) {
      $meta_data[$key_prefix . ucfirst($p)] = $entity->{$p}
        ->getString();
    }
  }

  // For entities with an owner/author, get the username.
  if (in_array('name', $properties) && !isset($meta_data[$key_prefix . 'Name']) && is_object($entity->uid) && $entity->uid->entity && $entity->uid->entity instanceof EntityInterface) {
    $meta_data[$key_prefix . 'Name'] = $entity->uid->entity
      ->label();
  }
  return $meta_data;
}