kirby-modules
kirby-modules copied to clipboard
Duplicate button
Hi trying to implement a duplicate button in the nav bar, but with no bigger luck, any help is highly appreciated ! The idea was a simple shortcut (the plus icon) for adding fields without having to open up the modal and select the desired field from a select. Thanks..
Added a new public function to the controller.php and a new route in modules.php
controller.php
public function dope($path) {
$path = explode('/', $path);
$self = $this;
$model = $this->model();
$cache = $this->cache($model);
$entry = $cache->get($path);
$types = array(
'type' => 'gallery'
);
$cache->add($path, $types);
$self->redirect($model);
}
But can´t figure out how to pass the type to the url('dope') function !? Now I just default it to "gallery"..
hmm ok got the right type working now by appending the entry->type() to the url and then "pop" it, but would like to push the new entry right after the one I would like to duplicate, now it get last..
public function adder($path) {
$path = explode('/', $path);
$self = $this;
$model = $this->model();
$cache = $this->cache($model);
$entry = $cache->get($path);
$type = array_pop($path);
$type = array(
'type' => $type
);
$cache->add($path, $type);
$self->redirect($model);
}
uhm ok I think I might over complicated things here.. oh dear..
It could probably just do exactly what the Add modules
button does;
https://github.com/frekw/kirby-modules/blob/master/fields/modules/template.php#L24
No.. I was thinking of creating a button that adds a "entry" with out having to open a modal and select it from there, see image. So if I push the plus sign it creates just another grid entry beneath the one I clicked. Hope I make sense.. If I have a gallery "entry" and hit the plus sign it creates a gallery entry and so on..
I am trying to send the entry type with href path on the button so I can duplicate the entry:
<a class="modules-entry-add" href="<?php __($field->url('adder') . '/' . $entry->type()) ?>"><?php i('plus') ?></a></li>
That's unfortunately really hard to do due to the way Kirby renders fields. Which is the reason why it's done via modal in the current implementation.
In order to do it you would pretty much need to export the module hierarchy to Javascript (e.g what module can be under another module), pick the "right" module, insert a hidden field into the entire form, submit it and reload the page.
It would be nice for the UX, though!
Well this works actually!
button :
<a class="modules-entry-add" href="<?php __($field->url('adder') . '/' . $entry->type()) ?>"><?php i('plus') ?></a></li>
function :
public function adder($path) {
$path = explode('/', $path);
$self = $this;
$model = $this->model();
$cache = $this->cache($model);
$entry = $cache->get($path);
$type = array_pop($path);
$type = array(
'type' => $type
);
$cache->add($path, $type);
$self->redirect($model);
}
routes :
array(
'pattern' => 'adder/(:all)',
'method' => 'get|post',
'action' => 'adder'
)
The only thing I am struggling with is the position of the newly created entry, it gets last, would like it to appear directly after the one I clicked..