<commit_before><?php

namespace Concrete\Core\Form\Service\Widget;

use Concrete\Core\Form\Service\Form;
use Concrete\Core\Http\Request;
use Concrete\Core\Http\ResponseAssetGroup;
use Concrete\Core\Tree\Node\Type\Group as GroupTreeNode;
use Concrete\Core\Tree\Type\Group as GroupTree;
use Concrete\Core\User\Group\Group;
use Concrete\Core\User\Group\GroupList;
use Concrete\Core\Utility\Service\Identifier;

class GroupSelector
{
    protected $assetGroup;

    protected $request;

    protected $formHelper;

    protected $groupList;

    public function __construct(Form $formHelper, GroupList $groupList)
    {
        $this->assetGroup = ResponseAssetGroup::get();
        $this->request = Request::getInstance();
        $this->formHelper = $formHelper;
        $this->groupList = $groupList;
    }

    /**
     * @param string $field
     * @param \Concrete\Core\User\Group\Group|int|mixed $group
     * @param string|null $noneText
     *
     * @return string
     */
    public function selectGroup($field, $group = null, $noneText = null)
    {
        if ($this->request->isMethod('POST') && $this->request->request->has($field)) {
            $group = $this->request->request->get($field);
        }
        if (is_numeric($group)) {
            $groupID = max((int) $group, 0);
        } elseif ($group instanceof Group) {
            $groupID = (int) ($group->getGroupID() ?? 0);
        } else {
            $groupID = 0;
        }
        $chooseText = (string) $noneText;
        if ($chooseText === '') {
            $chooseText = t('Choose a Group');
        }
        $identifier = app(Identifier::class)->getString(32);
        $htmlField = h($field);
        $htmlChooseText = h($chooseText);

        $selector = <<<EOT
<div data-concrete-group-input="{$identifier}">
    <concrete-group-input :group-id="{$groupID}" choose-text="{$htmlChooseText}" input-name="{$htmlField}"></concrete-group-input>
</div>
<script>
$(function() {
    Concrete.Vue.activateContext('cms', function (Vue, config) {
        new Vue({
            el: 'div[data-concrete-group-input="{$identifier}"]',
            components: config.components,
        })
    })
});
</script>
EOT;

        print $selector;
        ;
    }

    public function getGroupFromGroupTreeRequestValue($value)
    {
        // We have this helper method because you're not actually submitting a group ID – you're submitting a
        // group node ID. So we need to translate that into a group.
        if ($value) {
            $node = \Concrete\Core\Tree\Node\Type\Group::getByID($value);
            if ($node) {
                return $node->getTreeNodeGroupObject();
            }
        }
    }<commit_msg>Fix GroupSelector phpdoc<commit_after><?php

namespace Concrete\Core\Form\Service\Widget;

use Concrete\Core\Form\Service\Form;
use Concrete\Core\Http\Request;
use Concrete\Core\Http\ResponseAssetGroup;
use Concrete\Core\Tree\Node\Type\Group as GroupTreeNode;
use Concrete\Core\Tree\Type\Group as GroupTree;
use Concrete\Core\User\Group\Group;
use Concrete\Core\User\Group\GroupList;
use Concrete\Core\Utility\Service\Identifier;

class GroupSelector
{
    protected $assetGroup;

    protected $request;

    protected $formHelper;

    protected $groupList;

    public function __construct(Form $formHelper, GroupList $groupList)
    {
        $this->assetGroup = ResponseAssetGroup::get();
        $this->request = Request::getInstance();
        $this->formHelper = $formHelper;
        $this->groupList = $groupList;
    }

    /**
     * @param string $field
     * @param \Concrete\Core\User\Group\Group|int|mixed $group
     * @param string|null $noneText
     */
    public function selectGroup($field, $group = null, $noneText = null)
    {
        if ($this->request->isMethod('POST') && $this->request->request->has($field)) {
            $group = $this->request->request->get($field);
        }
        if (is_numeric($group)) {
            $groupID = max((int) $group, 0);
        } elseif ($group instanceof Group) {
            $groupID = (int) ($group->getGroupID() ?? 0);
        } else {
            $groupID = 0;
        }
        $chooseText = (string) $noneText;
        if ($chooseText === '') {
            $chooseText = t('Choose a Group');
        }
        $identifier = app(Identifier::class)->getString(32);
        $htmlField = h($field);
        $htmlChooseText = h($chooseText);

        $selector = <<<EOT
<div data-concrete-group-input="{$identifier}">
    <concrete-group-input :group-id="{$groupID}" choose-text="{$htmlChooseText}" input-name="{$htmlField}"></concrete-group-input>
</div>
<script>
$(function() {
    Concrete.Vue.activateContext('cms', function (Vue, config) {
        new Vue({
            el: 'div[data-concrete-group-input="{$identifier}"]',
            components: config.components,
        })
    })
});
</script>
EOT;

        print $selector;
    }

    public function getGroupFromGroupTreeRequestValue($value)
    {
        // We have this helper method because you're not actually submitting a group ID – you're submitting a
        // group node ID. So we need to translate that into a group.
        if ($value) {
            $node = \Concrete\Core\Tree\Node\Type\Group::getByID($value);
            if ($node) {
                return $node->getTreeNodeGroupObject();
            }
        }
    }
{'fraction_non_alphanumeric': 0.14856289660321015, 'fraction_numerical': 0.001866368047779022, 'mean_word_length': 2.591823056300268, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6954323', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1583, 'n_words': 334}