The problem of your function is returning 1 always is because you do the following
foreach ($tags as $tag)
{
$tagWeights[$tag['tag']] = (isset($tagWeights[$tag['tag']])) ? $tagWeights[$tag['tag']] + 1 : 1;
var_dump($tagWeights[$tag['tag']]);
}
And you iterate once for each tag, therefore $tagWeights[$tag['tag']] is not acceded more than once per tag, hence always has the value 1.
One way to do this, and thus you wouldn't have to change much code, would be use the blogs instead the tags as below:
foreach ($blogs as $blog)
{
foreach($blog->getTags() as $tag){
$tagWeights[$tag->getTag()] = (isset($tagWeights[$tag->getTag()])) ? $tagWeights[$tag->getTag()] + 1 : 1;
var_dump($tagWeights[$tag->getTag()]);
}
}
And you'd need to pass the $blogs variable to the function instead $tags
public function getTagWeights($blogs)
{
...
}
The code above is not tested, but it would be something similar.
I think that another problem is that in your Tag entity, you doesn't use the unique annotation for tag, and in this way, it's possible that there are some tags with exactly the same name, and it's not the expected behavior for the tags cloud. You should do something like this:
/**
* @var string
*
* @ORM\Column(name="tag", type="string", length=255, unique=true)
*/
private $tag;