I got an issue with one of the filters, or an object.
What it does
When upload an image to a Kirby page in the panel it uploads it and create a text-file with some debug info.
What don’t work
It says here how to get the page object…
http://forum.getkirby.com/t/how-can-i-get-the-parent-object-of-a-file/897
…but I don’t get this to work…
$file->page()->slug()
Example
Uncomment the row with slug() to make the example work.
<?php
kirby()->hook('panel.file.upload', 'run');
function run( $file ) {
$path = kirby()->roots()->content();
$content = '';
$content .= $file->page()->slug() . "\n";
$content .= $file->name();
file_put_contents( $path . '/test.txt', $content );
}
- How can I save the file page slug to the text-file?
- Is there an easier way to debug hooks than this?
EDIT:
I made a workaround, but it’s not so nice:
$file_bits = array_reverse( explode( '\\', $file->root() ) );
$slugs['parent'] = $file_bits[1];
$slugs['grandparent'] = $file_bits[2];