public function render(Entity $entity)
    {
        if (!isset($this->_View->viewVars['__commentComponentLoaded__'])) {
            throw new InternalErrorException(__d('comment', 'Illegal usage of \Comment\View\Helper\CommentHelper.'));
        }

        $this->config('entity', $entity);
        $event = $this->trigger(['CommentHelper.beforeRender', $this->_View]);
        if ($event->isStopped()) {
            return $event->result;
        }

        $out = '';
        if ($this->config('visibility') > 0) {
            $out .= $this->_View->element('Comment.render_comments_list');
            if ($this->config('visibility') === 1) {
                $out .= $this->_View->element('Comment.render_comments_form');
            }
        }

        $event = $this->trigger(['CommentHelper.afterRender', $this->_View], $out);
        if ($event->isStopped()) {
            return $event->result;
        }

        return $out;
    }