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

$fhf = new FieldHandlerFactory();

if (empty($user) && !empty($_SESSION)) {
    $user = Hash::get($_SESSION, 'Auth.User');
}

$menu = [];

list($plugin, $controller) = pluginSplit($options['class_name']);

$url = [
    'prefix' => false,
    'plugin' => $plugin,
    'controller' => $controller,
    'action' => 'view',
    $entity->id
];
$menu[] = [
    'html' => $this->Html->link('<i class="fa fa-eye"></i>', $url, [
        'title' => __('View'), 'class' => 'btn btn-default btn-sm', 'escape' => false
    ]),
    'url' => $url,
    'label' => __('View'),
    'icon' => 'eye',
    'type' => 'link_button',
    'order' => 10,
];

$url = [
    'prefix' => false,
    'plugin' => $plugin,
    'controller' => $controller,
    'action' => 'edit',
    $entity->id
];
$menu[] = [
    'html' => $this->Html->link('<i class="fa fa-pencil"></i>', $url, [
        'title' => __('Edit'), 'class' => 'btn btn-default btn-sm', 'escape' => false
    ]),
    'url' => $url,
    'label' => __('Edit'),
    'icon' => 'pencil',
    'type' => 'link_button',
    'order' => 20,
];

$url = [
    'prefix' => false,
    'plugin' => $plugin,
    'controller' => $controller,
    'action' => 'delete',
    $entity->id,
];

$menu[] = [
    'html' => $this->Form->postLink('<i class="fa fa-trash"></i>', $url, [
        'confirm' => __(
            'Are you sure you want to delete {0}?',
            $fhf->renderValue(
                $options['class_name'],
                $options['display_field'],
                $entity->{$options['display_field']},
                ['renderAs' => 'plain']
            )
        ),
        'title' => __('Delete'),
        'class' => 'btn btn-default btn-sm',
        'escape' => false
    ]),
    'url' => $url,
    'label' => __('Delete'),
    'icon' => 'trash',
    'type' => 'postlink_button',
    'order' => 40,
    'confirmMsg' => __(
        'Are you sure you want to delete {0}?',
        $fhf->renderValue(
            $options['class_name'],
            $options['display_field'],
            $entity->{$options['display_field']},
            ['renderAs' => 'plain']
        )
    ),
];

if (isset($options['associationType']) && in_array($options['associationType'], ['manyToMany'])) {
    $url = [
        'plugin' => $this->request->plugin,
        'controller' => $this->request->controller,
        'action' => 'unlink',
        $entity->id,
        $options['assoc_name'],
        $entity->id
    ];
    $menu[] = [
        'html' => $this->Form->postLink('<i class="fa fa-chain-broken"></i>', $url, [
            'title' => __('Unlink'), 'class' => 'btn btn-default btn-sm', 'escape' => false
        ]),
        'url' => $url,
        'label' => __('Unlink'),
        'icon' => 'unlink',
        'type' => 'postlink_button',
        'order' => 30,
    ];
}

// broadcast menu event
$event = new Event((string)EventName::MENU_ACTIONS_ASSOCIATED(), $this, [
    'menu' => $menu,
    'user' => $user,
    'type' => 'actions',
]);
$this->eventManager()->dispatch($event);

echo '<div class="btn-group btn-group-xs" role="group">' . $event->result . '</div>';
<commit_msg>Fixed unlink url (task #1329)<commit_after><?php
use Cake\Event\Event;
use Cake\Utility\Hash;
use CsvMigrations\Event\EventName;
use CsvMigrations\FieldHandlers\FieldHandlerFactory;

$fhf = new FieldHandlerFactory();

if (empty($user) && !empty($_SESSION)) {
    $user = Hash::get($_SESSION, 'Auth.User');
}

$menu = [];

list($plugin, $controller) = pluginSplit($options['associationName']);

$url = [
    'prefix' => false,
    'plugin' => $plugin,
    'controller' => $controller,
    'action' => 'view',
    $entity->id
];
$menu[] = [
    'html' => $this->Html->link('<i class="fa fa-eye"></i>', $url, [
        'title' => __('View'), 'class' => 'btn btn-default btn-sm', 'escape' => false
    ]),
    'url' => $url,
    'label' => __('View'),
    'icon' => 'eye',
    'type' => 'link_button',
    'order' => 10,
];

$url = [
    'prefix' => false,
    'plugin' => $plugin,
    'controller' => $controller,
    'action' => 'edit',
    $entity->id
];
$menu[] = [
    'html' => $this->Html->link('<i class="fa fa-pencil"></i>', $url, [
        'title' => __('Edit'), 'class' => 'btn btn-default btn-sm', 'escape' => false
    ]),
    'url' => $url,
    'label' => __('Edit'),
    'icon' => 'pencil',
    'type' => 'link_button',
    'order' => 20,
];

$url = [
    'prefix' => false,
    'plugin' => $plugin,
    'controller' => $controller,
    'action' => 'delete',
    $entity->id,
];

$menu[] = [
    'html' => $this->Form->postLink('<i class="fa fa-trash"></i>', $url, [
        'confirm' => __(
            'Are you sure you want to delete {0}?',
            $fhf->renderValue(
                $options['class_name'],
                $options['display_field'],
                $entity->{$options['display_field']},
                ['renderAs' => 'plain']
            )
        ),
        'title' => __('Delete'),
        'class' => 'btn btn-default btn-sm',
        'escape' => false
    ]),
    'url' => $url,
    'label' => __('Delete'),
    'icon' => 'trash',
    'type' => 'postlink_button',
    'order' => 40,
    'confirmMsg' => __(
        'Are you sure you want to delete {0}?',
        $fhf->renderValue(
            $options['class_name'],
            $options['display_field'],
            $entity->{$options['display_field']},
            ['renderAs' => 'plain']
        )
    ),
];

if (isset($options['associationType']) && in_array($options['associationType'], ['manyToMany'])) {
    $url = [
        'prefix' => false,
        'plugin' => $this->request->plugin,
        'controller' => $this->request->controller,
        'action' => 'unlink',
        $options['id'],
        $options['assoc_name'],
        $entity->id
    ];
    $menu[] = [
        'html' => $this->Form->postLink('<i class="fa fa-chain-broken"></i>', $url, [
            'title' => __('Unlink'), 'class' => 'btn btn-default btn-sm', 'escape' => false
        ]),
        'url' => $url,
        'label' => __('Unlink'),
        'icon' => 'unlink',
        'type' => 'postlink_button',
        'order' => 30,
    ];
}

// broadcast menu event
$event = new Event((string)EventName::MENU_ACTIONS_ASSOCIATED(), $this, [
    'menu' => $menu,
    'user' => $user,
    'type' => 'actions',
]);
$this->eventManager()->dispatch($event);

echo '<div class="btn-group btn-group-xs" role="group">' . $event->result . '</div>';

{'fraction_non_alphanumeric': 0.23541952185168266, 'fraction_numerical': 0.003654636820465966, 'mean_word_length': 2.5292853304674905, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 187, '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': '665983', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2234, 'n_words': 432}