<commit_before><?php
    /*
     * Generic form builder
     *
     * Simply pass a JSON with the following keys set:
     * - model: The model used to create the form (such as Attribute, Event)
     * - description: text description of the form
     * - fields: an array with each element generating an input field
     *     - field is the actual field name (such as org_id, name, etc) which is required
     *     - optional fields: default, type, options, placeholder, label - these are passed directly to $this->Form->input(),
     *     - requirements: boolean, if false is passed the field is skipped
     * - metafields: fields that are outside of the scope of the form itself
           - use these to define dynamic form fields, or anything that will feed into the regular fields via JS population
     * - submit: The submit button itself. By default it will simply submit to the form as defined via the 'model' field
     */
    $modelForForm = empty($data['model']) ?
        h(Inflector::singularize(Inflector::classify($this->request->params['controller']))) :
        h($data['model']);
    $fieldsString = '';
    $simpleFieldAllowedlist = array(
        'default', 'type', 'options', 'placeholder', 'label', 'empty', 'rows', 'div', 'required', 'checked', 'multiple', 'selected', 'legend',
        'disabled',
    );
    $fieldsArrayForPersistence = array();
    $formOptions = isset($formOptions) ? $formOptions : array();
    $formOptions = array_merge(['class' => 'genericForm'], $formOptions);
    $formCreate = $this->Form->create($modelForForm, $formOptions);
    if (!empty($data['fields'])) {
        foreach ($data['fields'] as $fieldData) {
            if (isset($fieldData['requirements']) && !$fieldData['requirements']) {
                continue;
            }
            if (is_array($fieldData)) {
                if (empty($fieldData['label'])) {
                    $fieldData['label'] = Inflector::humanize($fieldData['field']);
                }
                if (!empty($fieldDesc[$fieldData['field']])) {
                    $fieldData['label'] .= $this->element(
                        'genericElements/Form/formInfo', array(
                            'field' => $fieldData,
                            'fieldDesc' => $fieldDesc[$fieldData['field']],
                            'modelForForm' => $modelForForm
                        )
                    );
                }
                $params = array();
                if (!empty($fieldData['class'])) {
                    if (is_array($fieldData['class'])) {
                        $class = implode(' ', $fieldData['class']);
                    } else {
                        $class = $fieldData['class'];
                    }
                    $params['class'] = $class;
                } else {
                    if (!empty($fieldData['type']) && ($fieldData['type'] !== 'checkbox' && $fieldData['type'] !== 'radio')) {
                        $params['class'] = 'span6';
                    }
                }
                foreach ($simpleFieldAllowedlist as $f) {
                    if (!empty($fieldData[$f])) {
                        $params[$f] = $fieldData[$f];
                    }
                }
                if (!empty($fieldData['picker']) && isset($fieldData['picker']['function'])) {
                    $fieldData['picker']['text'] = isset($fieldData['picker']['text']) ? $fieldData['picker']['text'] : __('Picker');
                    $params['div'] = 'input text input-append';
                    $params['after'] = sprintf('<button type="button" class="btn" onclick="%s.call(this);">%s</button>', $fieldData['picker']['function'], __($fieldData['picker']['text']));
                }
                if (!empty($params['type']) && $params['type'] === 'dropdown') {
                    $params['type'] = 'select';
                }
                if (!empty($fieldData['description'])) {
                    if (!isset($params['class'])) {
                        $params['class'] = '';
                    }
                    $params['class'] .= ' input-with-description';
                }
                $temp = $this->Form->input($fieldData['field'], $params);
                if (!empty($fieldData['description'])) {
                    $temp .= sprintf('<small class="clear form-field-description apply_css_arrow">%s</small>', h($fieldData['description']));
                }
                $fieldsArrayForPersistence[] = $modelForForm . Inflector::camelize($fieldData['field']);
                if (!empty($fieldData['hidden'])) {
                    $temp = '<span class="hidden">' . $temp . '</span>';
                }
                $fieldsString .= $temp;
            } else {
                $fieldsString .= $fieldData;
            }
            if (empty($fieldData['stayInLine'])) {<commit_msg>fix: allow 0 or '0' to be a possible field value, for example 'selected' property.<commit_after><?php
    /*
     * Generic form builder
     *
     * Simply pass a JSON with the following keys set:
     * - model: The model used to create the form (such as Attribute, Event)
     * - description: text description of the form
     * - fields: an array with each element generating an input field
     *     - field is the actual field name (such as org_id, name, etc) which is required
     *     - optional fields: default, type, options, placeholder, label - these are passed directly to $this->Form->input(),
     *     - requirements: boolean, if false is passed the field is skipped
     * - metafields: fields that are outside of the scope of the form itself
           - use these to define dynamic form fields, or anything that will feed into the regular fields via JS population
     * - submit: The submit button itself. By default it will simply submit to the form as defined via the 'model' field
     */
    $modelForForm = empty($data['model']) ?
        h(Inflector::singularize(Inflector::classify($this->request->params['controller']))) :
        h($data['model']);
    $fieldsString = '';
    $simpleFieldAllowedlist = array(
        'default', 'type', 'options', 'placeholder', 'label', 'empty', 'rows', 'div', 'required', 'checked', 'multiple', 'selected', 'legend',
        'disabled',
    );
    $fieldsArrayForPersistence = array();
    $formOptions = isset($formOptions) ? $formOptions : array();
    $formOptions = array_merge(['class' => 'genericForm'], $formOptions);
    $formCreate = $this->Form->create($modelForForm, $formOptions);
    if (!empty($data['fields'])) {
        foreach ($data['fields'] as $fieldData) {
            if (isset($fieldData['requirements']) && !$fieldData['requirements']) {
                continue;
            }
            if (is_array($fieldData)) {
                if (empty($fieldData['label'])) {
                    $fieldData['label'] = Inflector::humanize($fieldData['field']);
                }
                if (!empty($fieldDesc[$fieldData['field']])) {
                    $fieldData['label'] .= $this->element(
                        'genericElements/Form/formInfo', array(
                            'field' => $fieldData,
                            'fieldDesc' => $fieldDesc[$fieldData['field']],
                            'modelForForm' => $modelForForm
                        )
                    );
                }
                $params = array();
                if (!empty($fieldData['class'])) {
                    if (is_array($fieldData['class'])) {
                        $class = implode(' ', $fieldData['class']);
                    } else {
                        $class = $fieldData['class'];
                    }
                    $params['class'] = $class;
                } else {
                    if (!empty($fieldData['type']) && ($fieldData['type'] !== 'checkbox' && $fieldData['type'] !== 'radio')) {
                        $params['class'] = 'span6';
                    }
                }
                foreach ($simpleFieldAllowedlist as $f) {
                    if (isset($fieldData[$f])) {
                        $params[$f] = $fieldData[$f];
                    }
                }
                if (!empty($fieldData['picker']) && isset($fieldData['picker']['function'])) {
                    $fieldData['picker']['text'] = isset($fieldData['picker']['text']) ? $fieldData['picker']['text'] : __('Picker');
                    $params['div'] = 'input text input-append';
                    $params['after'] = sprintf('<button type="button" class="btn" onclick="%s.call(this);">%s</button>', $fieldData['picker']['function'], __($fieldData['picker']['text']));
                }
                if (!empty($params['type']) && $params['type'] === 'dropdown') {
                    $params['type'] = 'select';
                }
                if (!empty($fieldData['description'])) {
                    if (!isset($params['class'])) {
                        $params['class'] = '';
                    }
                    $params['class'] .= ' input-with-description';
                }
                $temp = $this->Form->input($fieldData['field'], $params);
                if (!empty($fieldData['description'])) {
                    $temp .= sprintf('<small class="clear form-field-description apply_css_arrow">%s</small>', h($fieldData['description']));
                }
                $fieldsArrayForPersistence[] = $modelForForm . Inflector::camelize($fieldData['field']);
                if (!empty($fieldData['hidden'])) {
                    $temp = '<span class="hidden">' . $temp . '</span>';
                }
                $fieldsString .= $temp;
            } else {
                $fieldsString .= $fieldData;
            }
            if (empty($fieldData['stayInLine'])) {
{'fraction_non_alphanumeric': 0.1620738926311492, 'fraction_numerical': 0.0004082465809348847, 'mean_word_length': 1.8271783035199076, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 41, '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': '4665515', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2396, 'n_words': 576}