Author: francois
Date: 2010-03-22 17:05:36 +0100 (Mon, 22 Mar 2010)
New Revision: 28681

Modified:
   plugins/sfPropel15Plugin/trunk/README
   plugins/sfPropel15Plugin/trunk/lib/generator/sfPropelGenerator.class.php
Log:
[sfPropel15Plugin] yet another shortcut in admin list view

Modified: plugins/sfPropel15Plugin/trunk/README
===================================================================
--- plugins/sfPropel15Plugin/trunk/README       2010-03-22 16:00:06 UTC (rev 
28680)
+++ plugins/sfPropel15Plugin/trunk/README       2010-03-22 16:05:36 UTC (rev 
28681)
@@ -192,4 +192,30 @@
     [php]
     <?php echo link_to($author->getName(), 'book', array(), 
array('query_string' => 'filters[author_id]=' . $author->getId())) ?>
 
-This is very useful for partial lists, to link admin modules together.
\ No newline at end of file
+This is very useful for partial lists, to link admin modules together.
+
+### Cross-Linking Admin Modules ###
+
+In lists, related object columns often have to link to another admin generator 
module. For instance, in a list of `Books`, a column showing the `Author` name 
usually needs to link to the `edit` view in the `author` module for the current 
book author. You can implement this feature using a partial column:
+
+    [yaml]
+    # in generator.yml
+    list:
+      display: [title, _author]
+
+The partial column code is a one-liner, but it's quite tedious to repeat it 
many times:
+
+    [php]
+    // in modules/book/templates/_author.php
+    <?php echo link_to($book->getAuthor(), 'author_edit', $book->getAuthor) ?>
+
+The `admin15` theme provides a shortcut for this situation. Just define the 
`link_module` setting in the `Author` field configuration to point the `author` 
module, and you're good to go:
+
+    [yaml]
+    # in generator.yml
+    list:
+      display: [title, Author]
+      fields:
+        Author: { link_module: author }
+        
+You no longer need a partial for such simple cases. This should unclutter the 
`templates/` directory of your admin generator modules.
\ No newline at end of file

Modified: 
plugins/sfPropel15Plugin/trunk/lib/generator/sfPropelGenerator.class.php
===================================================================
--- plugins/sfPropel15Plugin/trunk/lib/generator/sfPropelGenerator.class.php    
2010-03-22 16:00:06 UTC (rev 28680)
+++ plugins/sfPropel15Plugin/trunk/lib/generator/sfPropelGenerator.class.php    
2010-03-22 16:05:36 UTC (rev 28681)
@@ -138,6 +138,29 @@
   }
 
   /**
+   * Returns HTML code for a field.
+   *
+   * @param sfModelGeneratorConfigurationField $field The field
+   *
+   * @return string HTML code
+   */
+  public function renderField($field)
+  {
+    if ($field->isLink() && ($module = $field->getConfig('link_module', false, 
false)))
+    {
+      $field->setLink(false);
+      $html = parent::renderField($field);
+      $field->setLink(true);
+      $html = sprintf("link_to(%s, '%s', %s)", $html, $module . '_edit', 
$html);
+      return $html;
+    }
+    else
+    {
+      return parent::renderField($field);
+    }
+  }
+  
+  /**
    * Returns the getter either non-developped: 'getFoo' or developped: 
'$class->getFoo()'.
    *
    * @param string  $column     The column name

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to