<commit_before><?php
use Cake\Event\Event;
use Cake\Utility\Inflector;
use CsvMigrations\FieldHandlers\FieldHandlerFactory;

$fhf = new FieldHandlerFactory();

$panels = [];
if (!empty($csvAssociatedRecords['oneToMany'])) {
    foreach ($csvAssociatedRecords['oneToMany'] as $tabName => $assocData) {
        if (0 === $assocData['records']->count()) {
            unset($csvAssociatedRecords['oneToMany'][$tabName]);
        } else {
            $panels[$tabName] = $csvAssociatedRecords['oneToMany'][$tabName];
        }
    }
}

/*
list of embedded fields to generate modals from
 */
$embFields = [];
if (!empty($csvAssociatedRecords['manyToMany'])) {
    foreach ($csvAssociatedRecords['manyToMany'] as $tabName => $assocData) {
        /*
        add to embedded fields
         */
        $embFields[] = $assocData['class_name'] . '.' . $assocData['foreign_key'];
        $panels[$tabName] = $csvAssociatedRecords['manyToMany'][$tabName];
    }
}
?>

<?php if (!empty($panels)) : ?>
<div class="row associated_records">
    <div class="col-xs-12">
        <hr />
        <ul id="relatedTabs" class="nav nav-tabs" role="tablist">
<?php
    $active = 'active';
    foreach ($panels as $tabName => $assocData) :
?>
            <li role="presentation" class="<?= $active; ?>">
                <a href="#<?= $tabName; ?>" aria-controls="<?= $tabName; ?>" role="tab" data-toggle="tab">
                    <?php
                        $tableName = Inflector::humanize($assocData['table_name']);
                        $fieldName = trim(str_replace($tableName, '', Inflector::humanize(Inflector::tableize($tabName))));
                        if (!empty($fieldName)) {
                            $fieldName = ' <small>(' . $fieldName . ')</small>';
                        }
                    ?>
                    <?= $tableName . $fieldName ?>
                </a>
            </li>
<?php
    $active = '';
    endforeach;
?>
        </ul>
        <div class="tab-content">
<?php
    $active = 'active';
    foreach ($panels as $assocName => $assocData) {
    ?>
            <div role="tabpanel" class="tab-pane <?= $active; ?>" id="<?= $assocName; ?>">
            <?php
            /*
            display typeahead field for adding/linking associated records,
            filtered from embeddedFields array.
             */
            $embField = $assocData['class_name'] . '.' . $assocData['foreign_key'];
            if (in_array($embField, $embFields)) : ?>
            <div class="row">
                <div class="typeahead-container col-md-4 col-md-offset-8">
                <?php
                    $formOptions = [
                        'url' => [
                            'plugin' => $this->request->plugin,
                            'controller' => $this->request->controller,
                            'action' => 'edit',
                            $this->request->pass[0]
                        ]
                    ];

                    echo $this->Form->create(null, $formOptions);
                    /*
                    non-embedded field
                     */
                    $tableName = $this->request->controller;
                    if (!is_null($this->request->plugin)) {
                        $tableName = $this->request->plugin . '.' . $tableName;
                    }

                    $handlerOptions = [];
                    /*
                    set associated table name to be used on input field's name
                     */
                    $handlerOptions['associated_table_name'] = $assocData['table_name'];
                    /*
                    set embedded modal flag
                     */
                    $handlerOptions['embModal'] = true;
                    /*
                    set field type to 'has_many' and default parameters
                     */
                    $handlerOptions['fieldDefinitions']['type'] = 'has_many(' . $assocData['class_name'] . ')';
                    $handlerOptions['fieldDefinitions']['required'] = true;
                    $handlerOptions['fieldDefinitions']['non-searchable'] = true;
                    $handlerOptions['fieldDefinitions']['unique'] = false;

                    /*
                    display typeahead field for associated module(s)
                     */
                    echo $fhf->renderInput(
                        $tableName,
                        $assocData['foreign_key'],
                        null,
                        $handlerOptions
                    );

                    /*
                    set existing related records as hidden fields
                     */
                    foreach ($assocData['records'] as $record) {
                        echo $this->Form->hidden($assocData['table_name'] . '._ids[]', [
                            'value' => $record->{$assocData['primary_key']}
                        ]);
                    }

                    echo $this->Form->end();
                ?>
                </div>
            </div>
            <?php endif; ?>

            <?php if (!empty($assocData['records'])) : ?>
                <div class=" table-responsive">
                    <table class="table table-hover table-datatable">
                        <thead>
                            <tr>
                            <?php foreach ($assocData['fields'] as $assocField) : ?>
                                <th><?= Inflector::humanize($assocField); ?></th>
                            <?php endforeach; ?>
                                <th class="actions"><?= __('Actions'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($assocData['records'] as $record) : ?>
                            <tr>
                            <?php foreach ($assocData['fields'] as $assocField) : ?>
                                <td>
                                <?php
                                    $renderOptions = [
                                        'entity' => $record,
                                        'renderAs' => 'plain'
                                    ];
                                    $value = $fhf->renderValue(
                                        $assocData['class_name'],
                                        $assocField,
                                        $record->$assocField,
                                        $renderOptions
                                    );

                                    if ($assocData['display_field'] === $assocField) {
                                        list($assocPlugin, $assocModel) = pluginSplit($assocData['class_name']);
                                        echo $this->Html->link(
                                            h($value), [
                                                'plugin' => $assocPlugin,
                                                'controller' => $assocModel,
                                                'action' => 'view',
                                                $record->$assocData['primary_key']
                                            ]
                                        );
                                    } else {
                                        echo !empty($value) ? $value : '&nbsp;';
                                    }
                                ?>
                                </td>
                            <?php endforeach; ?>
                            <td class="actions">
                            <?php
                                $event = new Event('View.Associated.Menu.Actions', $this, [
                                    'request' => $this->request,
                                    'options' => [
                                        'entity' => $entity,
                                        'assoc_entity' => $record,
                                        'assoc_name' => $assocData['assoc_name']
                                    ]<commit_msg>Disable escaping of rendered values in associated record listings<commit_after><?php
use Cake\Event\Event;
use Cake\Utility\Inflector;
use CsvMigrations\FieldHandlers\FieldHandlerFactory;

$fhf = new FieldHandlerFactory();

$panels = [];
if (!empty($csvAssociatedRecords['oneToMany'])) {
    foreach ($csvAssociatedRecords['oneToMany'] as $tabName => $assocData) {
        if (0 === $assocData['records']->count()) {
            unset($csvAssociatedRecords['oneToMany'][$tabName]);
        } else {
            $panels[$tabName] = $csvAssociatedRecords['oneToMany'][$tabName];
        }
    }
}

/*
list of embedded fields to generate modals from
 */
$embFields = [];
if (!empty($csvAssociatedRecords['manyToMany'])) {
    foreach ($csvAssociatedRecords['manyToMany'] as $tabName => $assocData) {
        /*
        add to embedded fields
         */
        $embFields[] = $assocData['class_name'] . '.' . $assocData['foreign_key'];
        $panels[$tabName] = $csvAssociatedRecords['manyToMany'][$tabName];
    }
}
?>

<?php if (!empty($panels)) : ?>
<div class="row associated_records">
    <div class="col-xs-12">
        <hr />
        <ul id="relatedTabs" class="nav nav-tabs" role="tablist">
<?php
    $active = 'active';
    foreach ($panels as $tabName => $assocData) :
?>
            <li role="presentation" class="<?= $active; ?>">
                <a href="#<?= $tabName; ?>" aria-controls="<?= $tabName; ?>" role="tab" data-toggle="tab">
                    <?php
                        $tableName = Inflector::humanize($assocData['table_name']);
                        $fieldName = trim(str_replace($tableName, '', Inflector::humanize(Inflector::tableize($tabName))));
                        if (!empty($fieldName)) {
                            $fieldName = ' <small>(' . $fieldName . ')</small>';
                        }
                    ?>
                    <?= $tableName . $fieldName ?>
                </a>
            </li>
<?php
    $active = '';
    endforeach;
?>
        </ul>
        <div class="tab-content">
<?php
    $active = 'active';
    foreach ($panels as $assocName => $assocData) {
    ?>
            <div role="tabpanel" class="tab-pane <?= $active; ?>" id="<?= $assocName; ?>">
            <?php
            /*
            display typeahead field for adding/linking associated records,
            filtered from embeddedFields array.
             */
            $embField = $assocData['class_name'] . '.' . $assocData['foreign_key'];
            if (in_array($embField, $embFields)) : ?>
            <div class="row">
                <div class="typeahead-container col-md-4 col-md-offset-8">
                <?php
                    $formOptions = [
                        'url' => [
                            'plugin' => $this->request->plugin,
                            'controller' => $this->request->controller,
                            'action' => 'edit',
                            $this->request->pass[0]
                        ]
                    ];

                    echo $this->Form->create(null, $formOptions);
                    /*
                    non-embedded field
                     */
                    $tableName = $this->request->controller;
                    if (!is_null($this->request->plugin)) {
                        $tableName = $this->request->plugin . '.' . $tableName;
                    }

                    $handlerOptions = [];
                    /*
                    set associated table name to be used on input field's name
                     */
                    $handlerOptions['associated_table_name'] = $assocData['table_name'];
                    /*
                    set embedded modal flag
                     */
                    $handlerOptions['embModal'] = true;
                    /*
                    set field type to 'has_many' and default parameters
                     */
                    $handlerOptions['fieldDefinitions']['type'] = 'has_many(' . $assocData['class_name'] . ')';
                    $handlerOptions['fieldDefinitions']['required'] = true;
                    $handlerOptions['fieldDefinitions']['non-searchable'] = true;
                    $handlerOptions['fieldDefinitions']['unique'] = false;

                    /*
                    display typeahead field for associated module(s)
                     */
                    echo $fhf->renderInput(
                        $tableName,
                        $assocData['foreign_key'],
                        null,
                        $handlerOptions
                    );

                    /*
                    set existing related records as hidden fields
                     */
                    foreach ($assocData['records'] as $record) {
                        echo $this->Form->hidden($assocData['table_name'] . '._ids[]', [
                            'value' => $record->{$assocData['primary_key']}
                        ]);
                    }

                    echo $this->Form->end();
                ?>
                </div>
            </div>
            <?php endif; ?>

            <?php if (!empty($assocData['records'])) : ?>
                <div class=" table-responsive">
                    <table class="table table-hover table-datatable">
                        <thead>
                            <tr>
                            <?php foreach ($assocData['fields'] as $assocField) : ?>
                                <th><?= Inflector::humanize($assocField); ?></th>
                            <?php endforeach; ?>
                                <th class="actions"><?= __('Actions'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($assocData['records'] as $record) : ?>
                            <tr>
                            <?php foreach ($assocData['fields'] as $assocField) : ?>
                                <td>
                                <?php
                                    $renderOptions = [
                                        'entity' => $record,
                                        'renderAs' => 'plain'
                                    ];
                                    $value = $fhf->renderValue(
                                        $assocData['class_name'],
                                        $assocField,
                                        $record->$assocField,
                                        $renderOptions
                                    );

                                    if ($assocData['display_field'] === $assocField) {
                                        list($assocPlugin, $assocModel) = pluginSplit($assocData['class_name']);
                                        // Not doing any escaping as it messes up display of
                                        // things like email fields with the mailto: link.
                                        echo $this->Html->link(
                                            $value, [
                                                'plugin' => $assocPlugin,
                                                'controller' => $assocModel,
                                                'action' => 'view',
                                                $record->$assocData['primary_key']
                                            ],
                                            ['escape' => false]
                                        );
                                    } else {
                                        echo !empty($value) ? $value : '&nbsp;';
                                    }
                                ?>
                                </td>
                            <?php endforeach; ?>
                            <td class="actions">
                            <?php
                                $event = new Event('View.Associated.Menu.Actions', $this, [
                                    'request' => $this->request,
                                    'options' => [
                                        'entity' => $entity,
                                        'assoc_entity' => $record,
                                        'assoc_name' => $assocData['assoc_name']
                                    ]
{'fraction_non_alphanumeric': 0.12861482381530984, 'fraction_numerical': 0.0007290400972053463, 'mean_word_length': 0.9825364326147176, 'pattern_counts': {'":': 0, '<': 117, '<?xml version=': 0, '>': 208, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 82, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '814177', 'n_tokens_mistral': 3790, 'n_tokens_neox': 3597, 'n_words': 686}