/** * Method that adds elements to associated Element actions menu. * * @param Cake\Event\Event $event Event object * @param Cake\Network\Request $request Request object * @param Cake\ORM\Entity $options Entity options * @return undefined */ public function getAssociatedMenuActions(Event $event, Request $request, array $options) { list($assocPlugin, $assocController) = pluginSplit($options['associated']['className']); $appView = $event->subject(); if (!$appView instanceof View) { $appView = new AppView(); } $controllerName = $request->controller; if (!empty($request->plugin)) { $controllerName = $request->plugin . '.' . $controllerName; } $urlView = ['prefix' => false, 'plugin' => $assocPlugin, 'controller' => $assocController, 'action' => 'view', $options['associated']['entity']->id]; $btnView = $appView->Html->link('', $urlView, ['title' => __('View'), 'class' => 'btn btn-default glyphicon glyphicon-eye-open']); $urlEdit = ['prefix' => false, 'plugin' => $assocPlugin, 'controller' => $assocController, 'action' => 'edit', $options['associated']['entity']->id]; $btnEdit = ' ' . $appView->Html->link('', $urlEdit, ['title' => __('Edit'), 'class' => 'btn btn-default glyphicon glyphicon-pencil']); $urlDel = ['prefix' => false, 'plugin' => $assocPlugin, 'controller' => $assocController, 'action' => 'delete', $options['associated']['entity']->id]; $btnDel = ' ' . $appView->Form->postLink('', $urlDel, ['confirm' => __('Are you sure you want to delete {0}?', $options['associated']['entity']->{$options['associated']['displayField']}), 'title' => __('Delete'), 'class' => 'btn btn-default glyphicon glyphicon-trash']); $menu = [['label' => $btnView, 'url' => $urlView], ['label' => $btnEdit, 'url' => $urlEdit], ['label' => $btnDel, 'url' => $urlDel]]; if (isset($options['associated']['type']) && in_array($options['associated']['type'], ['manyToMany'])) { $urlUnlink = ['plugin' => $request->plugin, 'controller' => $request->controller, 'action' => 'unlink', $options['entity']->id, $options['associated']['name'], $options['associated']['entity']->id]; $btnUnlink = ' ' . $appView->Form->postLink('', $urlUnlink, ['title' => __('Unlink'), 'class' => 'btn btn-default fa fa-chain-broken']); $menu[] = ['label' => $btnUnlink, 'url' => $urlUnlink]; } if ($appView->elementExists(static::MENU_ELEMENT)) { $result = $appView->element(static::MENU_ELEMENT, ['menu' => $menu, 'renderAs' => 'provided']); } else { $result = $btnUnlink; } return $result; }