Get ViewModel children by capture #5255

Merged
merged 11 commits into from Jan 3, 2014

Projects

None yet

3 participants

@jaapio

We wanted to add new content to the page view model using a listener. But in the MvcEvent pass to the listeners the view model is always the complete layout ViewModel and not only the page content model. So we needed a way to get a ViewModel by it's location in the template.

@Ocramius Ocramius commented on an outdated diff Oct 17, 2013
library/Zend/View/Model/ModelInterface.php
@@ -121,6 +121,15 @@ public function getChildren();
public function hasChildren();
/**
+ * Returns an array of ModelInterface with captureTo value $capture
+ *
+ * @param string $capture
+ * @param bool $recursive search recursive through children, default true
+ * @return array
+ */
+ public function getChildrenByCaptureTo($capture, $recursive = true);
@Ocramius
Ocramius Oct 17, 2013

This is a BC break

@jaapio

So I don't add it to the interface?

@Ocramius
Zend Framework member

@jaapio correct

@weierophinney weierophinney commented on the diff Oct 23, 2013
library/Zend/View/Model/ViewModel.php
@@ -381,6 +381,30 @@ public function clearChildren()
}
/**
+ * Returns an array of Viewmodels with captureTo value $capture
+ *
+ * @param string $capture
+ * @param bool $recursive search recursive through children, default true
+ * @return array
+ */
+ public function getChildrenByCaptureTo($capture, $recursive = true)
@weierophinney
weierophinney Oct 23, 2013

Alternate possibility: add a new interface, "RetrievableChildrenInterface" or similar, and have the ViewModel also implement that interface. That way we can combine the two interfaces (or have the ViewModelInterface extend it) in 3.0, and users can test for that interface prior to calling the method.

@jaapio

Sounds good, but before I start more modifications I would like to know if this will be merged any way. Because if you don't like our solution at all, it is better to close this pr. :-)

@weierophinney
Zend Framework member

@jaapio yes, I'll merge it after you make the changes. :)

@weierophinney weierophinney added a commit that referenced this pull request Jan 3, 2014
@weierophinney weierophinney Merge branch 'feature/5255' into develop
Close #5255
dda5d78
@weierophinney weierophinney merged commit cda48a9 into zendframework:develop Jan 3, 2014

1 check failed

Details default The Travis CI build failed
@weierophinney weierophinney was assigned Jan 3, 2014
@jaapio jaapio deleted the youngguns-nl:getChildrenByCapture branch Jan 8, 2014
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge pull request zendframework/zendframework#5255 from youngguns-nl…
…/getChildrenByCapture

Get ViewModel children by capture
fd47d62
@weierophinney weierophinney added a commit to zendframework/zend-view that referenced this pull request May 15, 2015
@weierophinney weierophinney Merge branch 'feature/5255' into develop 239d83f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment