private function prepareElements(array $elementsData, $acceptScalar = true)
    {
        $elements = [];
        foreach ($elementsData as $key => $data) {
            if (true === $acceptScalar && is_scalar($data)) {
                $elements[$key] = $data;
                continue;
            }

            if (!is_array($data)) {
                continue;
            }

            if (isset($data['type']) && isset($data['uid'])) {
                if (null !== $element = $this->findOneByTypeAndUid($data['type'], $data['uid'])) {
                    $elements[$key] = $element;
                }

                continue;
            }

            $elements[$key] = [];
            foreach ($data as $row) {
                if (
                    isset($row['type'])
                    && isset($row['uid'])
                    && null !== $element = $this->findOneByTypeAndUid($row['type'], $row['uid'])
                ) {
                    $elements[$key][] = $element;
                }
            }
        }

        return $elements;
    }