@param array $entities Entities

@return array
187987
private function buildCustomEntitiesMap(array $entities)
    {
        $map = [];

        foreach ($entities as $entity) {
            $entityClass = ClassUtils::getClass($entity);
            $objectHash = spl_object_hash($entity);

            foreach ($this->getCustomObjectMeta($entityClass) as $targetProperty => $params) {
                $initPropertyValue = $this->getPropertyValue($entity, $params['initPropertyValuePath']);

                if (empty($initPropertyValue)) {
                    continue;
                }
                if (!isset($map[$entityClass])) {
                    $map[$entityClass] = [];
                }
                if (!isset($map[$entityClass][$objectHash])) {
                    $map[$entityClass][$objectHash] = [];
                }

                $map[$entityClass][$objectHash][$targetProperty] = [
                    'class' => !empty($params['class'])
                        ? $params['class']
                        : $this->getPropertyValue($entity, $params['classPropertyPath'])
                    ,
                    'initProperty' => !empty($params['initProperty'])
                        ? $params['initProperty']
                        : $this->extendedMetadataFactory->getIdentifier($entityClass)
                    ,
                    'initPropertyValue' => $initPropertyValue,
                ];
            }
        }

        return $map;
    }
609692
protected function transform_db_records_to_entities(array $records) {
        $preprocessors = $this->get_preprocessors();
        $result = array_map(function($record) {
            return ['record' => $record];
        }, $records);

        $result = array_reduce(array_keys($preprocessors), function($carry, $preprocessor) use ($records, $preprocessors) {
            $step = $preprocessors[$preprocessor];
            $dependencies = $step->execute($records);

            foreach ($dependencies as $index => $dependency) {
                // Add the new dependency to the list.
                $carry[$index] = array_merge($carry[$index], [$preprocessor => $dependency]);
            }

            return $carry;
        }, $result);

        return $this->from_db_records($result);
    }
369033
protected function normaliseMessages($entities)
    {
        $messages = [];
        // Squash second and third levels together (class.key)
        foreach ($entities as $class => $keys) {
            // Check if namespace omits class
            if (!is_array($keys)) {
                $messages[$class] = $keys;
            } else {
                foreach ($keys as $key => $value) {
                    $fullKey = "{$class}.{$key}";
                    $messages[$fullKey] = $value;
                }
            }
        }
        ksort($messages);
        return $messages;
    }
778708
protected function hydratePivotRelation(array $entities)
    {
        // TODO (note) We should definitely get rid of the pivot in a next
        // release, as this is not quite relevant in a datamapper context.
        return array_map(function ($entity) {
            $entityWrapper = $this->factory->make($entity);

            $pivotAttributes = $this->cleanPivotAttributes($entityWrapper);
            $pivot = $this->newExistingPivot($pivotAttributes);
            $entityWrapper->setEntityAttribute('pivot', $pivot);

            $object = $entityWrapper->unwrap();

            return $object;
        }, $entities);
    }
331804
protected function getEntityDataArray(EntityInterface $entity)
    {
        $metadata = $this->getEntityMetadata();
        $array = [];
        
        foreach ($this->getHydrator()->extract($entity) as $sqlName => $value) {
            if ($sqlName !== $metadata->getIdentifier() && null !== $value) {
                $array[$metadata->getRawSQLName($metadata->getName($sqlName))] = $value;
            }
        }
        
        return $array;
    }
439647
public function validateAndFilterAccessEntities($accessEntities)
    {
        $entities = [];
        foreach ($accessEntities as $ae) {
            if ($ae->validate($this)) {
                $entities[] = $ae;
            }
        }

        return $entities;
    }
481813
protected function storeCollection($entities)
    {
        $this->adapter->beginTransaction();

        foreach ($entities as $entity) {
            $this->storeEntity($entity);
        }

        $this->adapter->commit();

        return $entities;
    }
940206
private function readClassProperties($entity)
    {
        $className = get_class($entity);
        if (isset($this->entityProperties[$className])) {
            return $this->entityProperties[$className];
        }

        $reflectionClass = new \ReflectionClass($entity);
        $inheritedProperties = array_merge($this->getParentProperties($reflectionClass), $reflectionClass->getProperties());

        $properties = [];
        foreach ($inheritedProperties as $property) {
            $properties[$property->getName()] = $property;
        }

        $this->entityProperties[$className] = $properties;

        return $properties;
    }
1340913
protected function loadEntities(array $entityIds)
    {
        if (count($entityIds) === 0) {
            return null;
        }

        $entities = [];

        // Create and store the entities associated with each Id
        foreach ($entityIds as $entityId) {
            $hash = $this->getEntityHashById($entityId);

            if ($hash === null) {
                return null;
            }

            $entities[] = $this->loadEntity($hash);
        }

        return $entities;
    }
337551
private function encapsulate($entities)
	{
		$items = [];

		foreach ($entities as $entity)
		{
			$items[] = Entity::fromMetadata($entity, $this);
		}

		return new Collection($items);
	}
1274851
public function getOptionsList(array $entities = []) {
    $options = [];

    if (!empty($entities)) {
      foreach ($entities as $entity) {
        $entity = explode('-', $entity);
        $entity_type = $entity[0];
        $bundle = $entity[1];
        // Get all entity condition plugin definitions.
        foreach ($this->getDefinitions() as $plugin_id => $plugin_definition) {
          if (!empty($entity)) {
            if (isset($plugin_definition['entities'][$entity_type])) {
              // If only entity type is set in plugin.
              if (empty($plugin_definition['entities'][$entity_type])) {
                $options[$plugin_id] = Html::escape($plugin_definition['label']);
              }
              // If entity type and bundle(s) are set in plugin.
              else {
                if (in_array($bundle, $plugin_definition['entities'][$entity_type])) {
                  $options[$plugin_id] = Html::escape($plugin_definition['label']);
                }
              }
            }
          }
          else {
            $options[$plugin_id] = Html::escape($plugin_definition['label']);
          }
        }
      }
    }

    return $options;
  }
331148
public function getSortableGroupsFieldByEntity($entity)
    {
        if (is_object($entity)) {
            $entity = ClassUtils::getClass($entity);
        }

        $groups = [];
        if (isset($this->sortableGroups['entities'][$entity])) {
            $groups = $this->sortableGroups['entities'][$entity];
        }

        return $groups;
    }
1040765
public function toDto(array $entities)
    {
        return array_map(function (Entity $entity) {
            return $this->assembler->toDto($entity);
        }, $entities);
    }
1346692
public function getClasses($items)
  {
    $result = [];
    foreach ($items as $item) {
      $result[] = new ClassEntity($item);
    }

    return $result;
  }
307410
protected function getTotal($entities)
    {
        $pager = $this->restParams->getPager();
        $entitiesNumber = count($entities);

        if (!$pager) {
            return $entitiesNumber;
        }

        $limit = $pager->getLimit();
        $offset = $pager->getOffset();

        if ($entitiesNumber === 0 && $offset === 0) {
            return 0;
        }

        return in_array($entitiesNumber, [0, $limit], true)
            ? count($this->service->search($this->restParams, true))
            : $offset + $entitiesNumber;
    }
535096
protected function getIdentifier($entity)
    {
        $entityId = json_decode($this->entityRegistry->getEntityId($entity), true);

        if (is_array($entityId)) {
            $identifier = [];

            foreach ($entityId as $key => $value) {
                $key              = strtolower(Normalise::toUnderscoreSeparated(Normalise::fromCamelCase($key)));
                $identifier[$key] = $value;
            }

            return $identifier;
        }

        $primary = $this->builder->getMeta(get_class($entity))->primary;

        return [$primary => $entityId];
    }
1126274
public function segments($entity) {
		$result = [];

		if (strpos($entity->name, '::') !== false) {
			list($class, $child) = explode('::', $entity->name, 2);
			$result[$entity->name] = $child;
			$result[] = '::';
		} else {
			$class = $entity->name;
		}
		$parts = explode('/', $class);
		while ($parts) {
			$result[implode('/', $parts)] = end($parts);

			array_pop($parts);
			if ($parts) {
				$result[] = '\\';
			}
		}
		return array_reverse($result);
	}