Skip to content

Commit 6dd144b

Browse files
lorenzomarkstory
authored andcommitted
Adding getTemplate to view task
Signed-off-by: Mark Story <mark@mark-story.com>
1 parent 32198c5 commit 6dd144b

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

cake/console/libs/tasks/view.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -370,42 +370,51 @@ function bake($action, $content = '') {
370370
/**
371371
* Builds content from template and variables
372372
*
373-
* @param string $template file to use
373+
* @param string $action name to generate content to
374374
* @param array $vars passed for use in templates
375375
* @return string content from template
376376
* @access public
377377
*/
378-
function getContent($template = null, $vars = null) {
379-
if (!$template) {
380-
$template = $this->template;
381-
}
382-
$action = $template;
383-
384-
$adminRoute = Configure::read('Routing.admin');
385-
if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) {
386-
$template = str_replace($adminRoute . '_', '', $template);
387-
}
388-
if (in_array($template, array('add', 'edit'))) {
389-
$action = $template;
390-
$template = 'form';
391-
} elseif (preg_match('@(_add|_edit)$@', $template)) {
392-
$action = $template;
393-
$template = str_replace(array('_add', '_edit'), '_form', $template);
394-
}
378+
function getContent($action, $vars = null) {
395379
if (!$vars) {
396380
$vars = $this->__loadController();
397381
}
398382

399383
$this->Template->set('action', $action);
400384
$this->Template->set('plugin', $this->plugin);
401385
$this->Template->set($vars);
402-
$output = $this->Template->generate('views', $template);
386+
$output = $this->Template->generate('views', $this->getTemplate($action));
403387

404388
if (!empty($output)) {
405389
return $output;
406390
}
407391
return false;
408392
}
393+
394+
/**
395+
* Gets the template name based on the action name
396+
*
397+
* @param string $action name
398+
* @return string template name
399+
* @access public
400+
*/
401+
function getTemplate($action) {
402+
if (!empty($this->template) && $action != $this->template) {
403+
return $this->template;
404+
}
405+
$template = $action;
406+
$adminRoute = Configure::read('Routing.admin');
407+
if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) {
408+
$template = str_replace($adminRoute . '_', '', $template);
409+
}
410+
if (in_array($template, array('add', 'edit'))) {
411+
$template = 'form';
412+
} elseif (preg_match('@(_add|_edit)$@', $template)) {
413+
$template = str_replace(array('_add', '_edit'), '_form', $template);
414+
}
415+
return $template;
416+
}
417+
409418

410419
/**
411420
* Displays help contents

0 commit comments

Comments
 (0)