Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added properties and methods to keep up with use of childrenAttributes #140

Merged
merged 1 commit into from

5 participants

@petesiss

Added childrenAttributes and childrenAttributeKeys to allow for styling the UL menu element, following this update to KnpLabs/KnpMenu#31

@uwej711 uwej711 was assigned
@lsmith77
Owner

I keep wondering if we should make hash maps a high level ODM feature. Or maybe at least look into making it possible to add this as a custom data type (http://www.doctrine-project.org/jira/browse/PHPCR-43)

@uwej711
Collaborator

Do we need to update KnpMenu and KnpMenuBundle in the sandbox to make this work?

@stof

@uwej711 children attributes are in KnpMenu since a long time. The recent change is that they are also used for the route node now instead of having a special case for it using attributes on the ul.

@petesiss

Yes, will need the versions in the sandbox updating as it is in response to a recent BC break. What would be the best way to do that? Just set up in a new sandbox install and manually test against a newer KnpMenu version?

@stof

and btw, I indeed find it weird to have to emulate hash maps in your documents. The ODM should support it (or even PHPCR).

@lsmith77
Owner

JCR doesn't support hash maps, though maybe given that JCR defines an XML DB, maybe today it should also define a JSON store. But yeah, at the very least we could emulate it in PHPCR ODM.

@uwej711
Collaborator

@stof, @lsmith77: implementing hash maps could be done as in the ORM, serialize to a string. But maybe a child node would actually be more "JCR", $node->getPropertiesValues() actually returns a hash map ...

@petesiss

If all the menuItem objects need to investigate their children to be constructed - i.e. to collate any attributes etc - is that likely to have a performance penalty? Im completely new to Jackrabbit so no idea. Or maybe the entire menu tree has been queried already?

@uwej711
Collaborator

Yes there will be a performance penalty ... as far as I know we currently fetch nodes from the repository using the path and each time this might end up being a request to jackrabbit. Maybe the APIs used for querying (which I haven't used so far) allow for fetching more than a node at once (e.g. fetch a complete subtree or a subtree with a given depth or all ancestors). But this is getting off topic ... see http://www.doctrine-project.org/jira/browse/PHPCR-55

@dbu
Owner

i think we should provide hashmaps in the odm and emulate them on phpcr for now. then we can talk with the jcr guys if this can be added to the next jcr version.

i created a ticket on phcpr-odm and invite you to discuss there
http://www.doctrine-project.org/jira/browse/PHPCR-56

until thats done, does anybody want to update the sandbox and merge this pull request?

@dbu
Owner

@uwej711 should we merge this as well now? any problem with it?

@uwej711
Collaborator

No problem with that but I haven't tried it myself.

@dbu dbu merged commit 590124f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 0 deletions.
  1. +35 −0 src/Symfony/Cmf/Bundle/MenuBundle/Document/MenuItem.php
View
35 src/Symfony/Cmf/Bundle/MenuBundle/Document/MenuItem.php
@@ -58,6 +58,20 @@ class MenuItem implements NodeInterface {
*/
protected $attributes;
+ /**
+ * Simulate a php hashmap in phpcr. This holds the keys.
+ *
+ * @PHPCRODM\String(multivalue=true)
+ */
+ protected $childrenAttributeKeys;
+
+ /**
+ * Simulate a php hashmap in phpcr.
+ *
+ * @PHPCRODM\String(multivalue=true)
+ */
+ protected $childrenAttributes;
+
/** @PHPCRODM\Children(filter="*item") */
protected $children;
@@ -166,6 +180,26 @@ public function setAttributes($attributes)
$this->attributeKeys = array_keys($attributes);
}
+ public function getChildrenAttributes()
+ {
+ if (is_null($this->childrenAttributeKeys)) {
+ return array();
+ }
+ $keys = $this->childrenAttributeKeys instanceof Collection ?
+ $this->childrenAttributeKeys->toArray() :
+ $this->childrenAttributeKeys;
+ $values = $this->childrenAttributes instanceof Collection ?
+ $this->childrenAttributes->toArray() :
+ $this->childrenAttributes;
+ return array_combine($keys, $values);
+ }
+
+ public function setChildrenAttributes($attributes)
+ {
+ $this->childrenAttributes = $attributes;
+ $this->childrenAttributeKeys = array_keys($attributes);
+ }
+
public function getChildren()
{
return $this->children;
@@ -178,6 +212,7 @@ public function getOptions()
'route' => $this->getRoute(),
'label' => $this->getLabel(),
'attributes' => $this->getAttributes(),
+ 'childrenAttributes' => $this->getChildrenAttributes(),
'display' => true,
'displayChildren' => true,
'content' => $this->getContent(),
Something went wrong with that request. Please try again.