Make Partial proxy to view render function #2957

Closed
wants to merge 3 commits into from

2 participants

@bakura10

No description provided.

@weierophinney weierophinney commented on an outdated diff Nov 13, 2012
library/Zend/View/Helper/Partial.php
- $view->partialCounter = $this->partialCounter;
- }
-
- if (!empty($model)) {
- if (is_array($model)) {
- $view->vars()->assign($model);
- } elseif (is_object($model)) {
- if (null !== ($objectKey = $this->getObjectKey())) {
- $view->vars()->offsetSet($objectKey, $model);
- } elseif (method_exists($model, 'toArray')) {
- $view->vars()->assign($model->toArray());
- } else {
- $view->vars()->assign(get_object_vars($model));
- }
- }
- }
@weierophinney
Zend Framework member

We should keep the logic in this conditional; otherwise we break all backwards compatibility for the helper. Do the following:

  • If the model is a scalar, reset it to an empty array
  • If the model is a non-ModelInterface, non-View\Variables object, do the logic in the "elseif (is_object($model))" conditional, and capture the results to a variable

Then pass the model as an argument to render() (which you already do).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney commented on the diff Nov 19, 2012
library/Zend/View/Helper/Partial.php
- }
-
- if (!empty($model)) {
- if (is_array($model)) {
- $view->vars()->assign($model);
- } elseif (is_object($model)) {
- if (null !== ($objectKey = $this->getObjectKey())) {
- $view->vars()->offsetSet($objectKey, $model);
- } elseif (method_exists($model, 'toArray')) {
- $view->vars()->assign($model->toArray());
- } else {
- $view->vars()->assign(get_object_vars($model));
- }
+ if (is_scalar($values)) {
+ $values = array();
+ } elseif (is_object($values)) {
@weierophinney
Zend Framework member

Make this:

} elseif ($values instanceof \Zend\View\Model\ModelInterface) {
    $values = $values->getVariables();
} elseif (is_object($values)) {
   ... 

(importing ModelInterface, of course). The reason being that we can't count on a View Model implementation implementing the various bits that the next conditional looks at, but we can count on getVariables().

@weierophinney
Zend Framework member

Actually, we should probably check if $name is a View Model -- that could simplify things, too. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney commented on the diff Nov 19, 2012
library/Zend/View/Helper/Partial.php
{
if (0 == func_num_args()) {
return $this;
}
- $view = $this->cloneView();
- if (isset($this->partialCounter)) {
- $view->partialCounter = $this->partialCounter;
- }
-
- if (!empty($model)) {
- if (is_array($model)) {
- $view->vars()->assign($model);
- } elseif (is_object($model)) {
- if (null !== ($objectKey = $this->getObjectKey())) {
- $view->vars()->offsetSet($objectKey, $model);
- } elseif (method_exists($model, 'toArray')) {
@weierophinney
Zend Framework member

We need to keep the object key functionality as well; removing it is a BC break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney added a commit that referenced this pull request Nov 19, 2012
@weierophinney weierophinney [#2957] Cleanup
- To keep backwards compatibility:
  - re-instated "object key" functionality
- For forwards compatibility:
  - allow specifying a view model as the sole argument
  - pull variables from the view model when passed as the second argument
6940e30
@weierophinney weierophinney added a commit that referenced this pull request Nov 19, 2012
@weierophinney weierophinney Merge branch 'hotfix/2957' into develop
Forward port #2957
2e7d402
@weierophinney weierophinney added a commit that closed this pull request Nov 19, 2012
@weierophinney weierophinney Merge branch 'hotfix/2957'
Close #2957
fea78d5
@weierophinney
Zend Framework member

Re-introduced the "object key", and also ensured that a ViewModel instance can be used as the sole or second argument to partial(). Merged.

@ghost Unknown pushed a commit that referenced this pull request Jul 14, 2013
@weierophinney weierophinney [#2957] Cleanup
- To keep backwards compatibility:
  - re-instated "object key" functionality
- For forwards compatibility:
  - allow specifying a view model as the sole argument
  - pull variables from the view model when passed as the second argument
cd98d47
@ghost Unknown pushed a commit that referenced this pull request Jul 14, 2013
@weierophinney weierophinney Merge branch 'hotfix/2957'
Close #2957
081446e
@ghost Unknown pushed a commit that referenced this pull request Jul 14, 2013
@weierophinney weierophinney Merge branch 'hotfix/2957' into develop
Forward port #2957
d63be4a
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney [zendframework/zendframework#2957] Cleanup
- To keep backwards compatibility:
  - re-instated "object key" functionality
- For forwards compatibility:
  - allow specifying a view model as the sole argument
  - pull variables from the view model when passed as the second argument
3c86a67
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/2957' 32cf329
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/2957' into develop 12ddca8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment