Adding audio files for talks

Hi all -

I’ve had a group come to me who do talks, and want to list those talks online to stream. I figured I can just do this with a html5 player (noticed this: https://github.com/fanningert/kirbycms-extension-audio)

Question I have is based on the best practice for taxonomy - first thought was to simply creative a ‘talks’ page with every new talk being a child, and the blueprint can simply have ‘file’, ‘talk title’, ‘date’ and ‘speaker name’. However after a while it could end up with hundreds of child pages which I guess is fine but I wondered if there might be another way. Ideally the user go to the ‘talks’ page in the panel and add a new talk there which would bring up the fields for a talk as a kind of blueprint set , but I’m not aware of this being possible. Am I right?

Currently, when you create a new page, you have to fill in the “page create modal” before you get to the set of fields to fill in.

As regards page structure, if you expect to have more than a couple of hundreds of talks, I’d recommend to use subpages, maybe by speaker or category.

Then you can use additional categories in the page blueprint, whatever is needed.

I have done something like this with the sortable field. Have a look at the example extension to the plugin. You don’t have to actually use the plugin but perhaps you get the idea of how to setup your own Add form with a custom set of fields. The actual form / view etc. can be found here.

If you have a limit set of entries the sortable plugin might suit your needs but if there are hundreds of pages / talks a plugin with just a custom Add form would be better I think.


I put something together on how to modify the default add form for a specific route.
It is still the basic add form and controller but you can easily add more fields. Keep in mind that you need to modify the controller as well to store any new field values to the new page.

1 Like

Thanks. Is the reason to limit to around 200 purely for performance or more of a management issue?

Woah this is crazy - good stuff, thanks! Do you by any chance have a screenshot of the talks form? Would just help me get my head around it (I’m a UI designer so a little slow at some of the backend stuff, but I’m trying to learn!)

Have a look here.
This is the form that is shown right now.

To add a new field you can actually use the same syntax as any blueprint field. Only that it is not written in yml but in php.

Example for a date field

<?php
$form = new Kirby\Panel\Form(array(
  'title' => array(
    'label'        => 'pages.add.title.label',
    'type'         => 'title',
    'placeholder'  => 'pages.add.title.placeholder',
    'autocomplete' => false,
    'autofocus'    => true,
    'required'     => true
  ),
  'uid' => array(
    'label'        => 'pages.add.url.label',
    'type'         => 'text',
    'icon'         => 'chain',
    'autocomplete' => false,
    'required'     => true,
  ),
  'date' => array(
    'label'    => 'Date',
    'type'     => 'date',
    'format'   => 'MM/DD/YY',
    'default'  => 'today',
    'required' => true,
  ),
  'template' => array(
    'label'    => 'pages.add.template.label',
    'type'     => 'select',
    'options'  => $options,
    'default'  => key($options),
    'required' => true,
    'readonly' => count($options) == 1 ? true : false,
    'icon'     => count($options) == 1 ? $page->blueprint()->pages()->template()->first()->icon() : 'chevron-down',
  )
));

The controller should look something like this.

$form = panel()->form(__DIR__ . DS . 'form.php', $parent, function($form) use($parent, $controller) {
  try {
    $form->validate();
    if(!$form->isValid()) {
      throw new Exception(l('pages.add.error.template'));
    }
    $data = $form->serialize();
    $page = $parent->children()->create($data['uid'], $data['template'], array(
      'title' => $data['title'],
      'date'  => $data['date'], // this is what changed
    ));
    $controller->notify(':)');
    $controller->redirect($page, 'edit');
  } catch(Exception $e) {
    $form->alert($e->getMessage());
  }
});

I only took the parts of the code here that are important for the functionality.

No, 200 is not the limit at all, I actually did a test with 1000 subpages in a subdirectory once and while that slowed the Panel down a little bit, it did not become unusable at all.

@lukaskleinschmidt thanks for sharing the plugin!
I’m testing it but can’t make it work (I’m new to the use of plugins in general so I’m probably missing something…). Here’s what I did:

  • placed unzipped files in plugin folder as described
  • edited line 13 with the name of the parent template corso that will create the subpage corso-turno clicking “Add” (or does it want the subpage template? I tried that as well anyway )
  • edited form.php adding the date field and custom-add-form.phpas you described above

When I click Add I see the same old form.

To see if the plugin is loaded i tried a::show(kirby()->plugins) which prints:

Array
(
    [custom-add-form] => 
)

What am I missing here? Thx for any help.

What does line 13 look like now?

...
if($parent->intendedTemplate() !== 'corso-turno') {
...

You have to use the name of the parent template, not the child…

What this line does is check if the intended template of the parent page is different from the given one. If yes, it uses the default form. If no, then it uses the new form.

I have already tried that as well…

Hm, I know that it works and the plugin seems to be installed correctly, otherwise it wouldn’t show up.

Sure you have followed all the instructions by. the word?

It seems so to me… Here’s my plugins folder:

plugins/
  custom-add-form/
    custom-add-form.php     (added template at line 13 and added the field in the controller)
    form.php                (added date input as shown above)
    template.php            (untouched)

custom-add-form.php

form.php

And this line reads

if($parent->intendedTemplate() !== 'corso') {

and there is a parent page with a corso.txt in it?

Yes

Yes: corso is the template of the page where I am clicking “Add” to create a child of type corso-turno (I’m making the site of a school. corso is a course and its children pages are the available dates for that course).

I just tested it on a fresh startkit and it is working for me for blog template for example.
Can you please post the full content of the custom-add-form.php file.

Although there is a small error (the use($template) should not be there) in the custom-add-form.php it should still work.

Do you have debugging enabled?

Edit:
Already fixed it in the git repo. Here is the erroneous line just for reference.

<?php

if(!function_exists('panel')) return;

panel()->routes(array(
  array(
    'pattern' => 'pages/(:any)/add',
    'action'  => function($id) use($template) { // this line
      $panel  = panel();
      $parent = $panel->page($id);
      ...