private function form_template($episode_asset, $action, $button_text = NULL) { $raw_formats = \Podlove\Model\FileType::all(); $formats = array(); foreach ($raw_formats as $format) { $formats[$format->id] = array('title' => $format->title(), 'name' => $format->name, 'extension' => $format->extension, 'type' => $format->type); } $format_optionlist = array_map(function ($f) { return array('value' => $f['title'], 'attributes' => 'data-type="' . $f['type'] . '" data-extension="' . $f['extension'] . '" data-name="' . $f['name'] . '"'); }, $formats); $form_args = array('context' => 'podlove_episode_asset', 'hidden' => array('episode_asset' => $episode_asset->id, 'action' => $action), 'attributes' => array('id' => 'podlove_episode_assets'), 'submit_button' => false, 'form_end' => function () { echo "<p>"; submit_button(__('Save Changes'), 'primary', 'submit', false); echo " "; submit_button(__('Save Changes and Continue Editing', 'podlove'), 'secondary', 'submit_and_stay', false); echo "</p>"; }); \Podlove\Form\build_for($episode_asset, $form_args, function ($form) use($format_optionlist) { $f = new \Podlove\Form\Input\TableWrapper($form); if ($form->object->file_type_id) { $current_file_type = Model\FileType::find_by_id($form->object->file_type_id)->type; } else { $current_file_type = ''; } ?> <tr class="row_podlove_episode_asset_type"> <th scope="row" valign="top"> <label for="podlove_episode_asset_type"><?php echo __('Asset Type', 'podlove'); ?> </label> </th> <td> <select name="podlove_episode_asset_type" id="podlove_episode_asset_type"> <option><?php echo __('Please choose ...', 'podlove'); ?> </option> <?php foreach (Model\FileType::get_types() as $type) { ?> <option value="<?php echo $type; ?> " <?php selected($type, $current_file_type); ?> ><?php echo $type; ?> </option> <?php } ?> </select> <div id="option_storage" style="display:none"></div> </td> </tr> <?php $f->select('file_type_id', array('label' => __('File Format', 'podlove'), 'description' => __('', 'podlove'), 'options' => $format_optionlist)); $f->string('title', array('label' => __('Title', 'podlove'), 'description' => __('Description to identify the media file type to the user in download buttons.', 'podlove'), 'html' => array('class' => 'regular-text required podlove-check-input'))); $f->checkbox('downloadable', array('label' => __('Downloadable', 'podlove'), 'description' => sprintf('Allow downloads for users.', 'podlove'), 'default' => true)); ?> <tr> <th colspan="2"> <h3><?php echo __('Asset File Name', 'podlove'); ?> </h3> </th> </tr> <?php $f->string('suffix', array('label' => __('File Name Suffix', 'podlove'), 'description' => __('Optional. Is appended to file name after episode slug.', 'podlove'), 'html' => array('class' => 'regular-text required podlove-check-input'))); ?> <tr class="row_podlove_asset_url_preview"> <th> <?php echo __('URL Preview', 'podlove'); ?> </th> <td> <div id="url_preview" style="font-size: 1.5em"></div> <div id="url_template" style="display: none;"><?php echo Model\Podcast::get()->get_url_template(); ?> </div> </td> </tr> <?php }); // hidden fields for JavaScript ?> <input type="hidden" id="podlove_show_media_file_base_uri" value="<?php echo Model\Podcast::get()->media_file_base_uri; ?> "> <?php }
private function form_template($format, $action, $button_text = NULL) { $form_args = array('context' => 'podlove_file_type', 'hidden' => array('file_type' => $format->id, 'action' => $action, 'podlove_tab' => $_REQUEST['podlove_tab']), 'submit_button' => false, 'form_end' => function () { echo "<p>"; submit_button(__('Save Changes'), 'primary', 'submit', false); echo " "; submit_button(__('Save Changes and Continue Editing', 'podlove'), 'secondary', 'submit_and_stay', false); echo "</p>"; }); \Podlove\Form\build_for($format, $form_args, function ($form) { $wrapper = new \Podlove\Form\Input\TableWrapper($form); $types = array(); foreach (\Podlove\Model\FileType::get_types() as $type) { $types[$type] = $type; } $wrapper->string('name', array('label' => __('Name', 'podlove'), 'html' => array('class' => 'podlove-check-input'), 'description' => '')); $wrapper->select('type', array('label' => __('Document Type', 'podlove'), 'options' => $types)); $wrapper->string('mime_type', array('label' => __('Format Mime Type', 'podlove'), 'html' => array('class' => 'podlove-check-input'), 'description' => __('Example: audio/mp4', 'podlove'))); $wrapper->string('extension', array('label' => __('Format Extension', 'podlove'), 'html' => array('class' => 'podlove-check-input'), 'description' => __('Example: m4a', 'podlove'))); }); }