views:

243

answers:

1

Hi there,

I've been having some 'issues' with the admin generator (Propel version). The HTML generation behavior between the list view and the form view is very different, and I'd like to know why, as the form view works better (and as expected) compared to the list view.

I have the following YAML for the 'edit' action,

edit:
  actions:
    custom: { confirm: 'Run this custom action?' }
    _list:  ~
    _save:  ~

This generates the following HTML/PHP for the custom action specified,

// Snip ...
<li class="sf_admin_action_custom">
<?php if (method_exists($helper, 'linkToCustom')): ?>
  <?php echo $helper->linkToCustom($form->getObject(), array(  'confirm' => 'Run this custom action?',  'params' =>   array(  ),  'class_suffix' => 'custom',  'label' => 'Custom',)) ?>
<?php else: ?>
  <?php echo link_to(__('Custom', array(), 'messages'), 'users/ListCustom?id='.$user->getId(), array()) ?>
<?php endif; ?>
</li>
// Snip ...

Now, if I add my custom action to the YAML for the list view,

list:
  object_actions:
    custom:  { confirm: 'Run this custom action?' }
    _edit:   ~
    _delete: ~

I get the following HTML generated,

// Snip ...
<li class="sf_admin_action_custom">
  <?php echo link_to(__('Custom', array(), 'messages'), 'users/ListCustom?id='.$user->getId(), array()) ?>
</li>
// Snip ...

There's some distinct differences here that I find very odd,

  1. The form actions code checks to see if there is a method on the helper, and uses it if so, falling back to a standard link_to() function if not. However, the list actions code just uses the link_to() function, not even trying to use the helper.
  2. The form actions code passes my custom confirm message to the custom helper method, but neither templates pass it to the link_to(). Why is this? I'm hoping this is a bug.

If someone could shed some light as to why the two generate differently, I'd really appreciate it.

Thank you.

A: 

The admin generator uses templates that generates the above HTML/PHP. The default theme is located at:

sfConfig::get('sf_symfony_lib_dir')/plugins/sfPropelPlugin/data/generator/sfPropelModule/admin/. (version 1.2)

or

$sf_symfony_data_dir/generator/sfPropelAdmin/default/ (version 1.0)

The HTML/PHP code differs because the templates used to generate these files are different, but you can modify them to your likings by creating your own theme and specify that in the generator.yml. E.g.:

generator:
  class: sfPropelGenerator
  param:
    model_class:           BlogArticle
    theme:                 customTheme

For more information about how to do that, read http://www.symfony-project.org/book/1_2/14-Generators

Arjan
I could, and am now, use a custom generator. However, there are bugs and differences in the default theme for reasons I can't seem to understand. I submitted a ticket on the symfony trac. It just seems wrong to me.
Stephen Melrose
Although I don't think this is the 'right' answer, it solves my issue and is the closest I'll get. Cheers.
Stephen Melrose