Skip to content
This repository

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

Merged
merged 1 commit into from about 2 years ago

5 participants

Pete Sisson Lukas Kahwe Smith Uwe Jäger Christophe Coevoet David Buchmann
Pete Sisson

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

Lukas Kahwe Smith
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)

Uwe Jäger
Collaborator

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

Christophe Coevoet

@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.

Pete Sisson

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?

Christophe Coevoet

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

Lukas Kahwe Smith
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.

Uwe Jäger
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 ...

Pete Sisson

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?

Uwe Jäger
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

David Buchmann
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?

David Buchmann
Owner
dbu commented

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

Uwe Jäger
Collaborator

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

David Buchmann dbu merged commit 590124f into from
David Buchmann dbu closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 22, 2012
Pete Sisson Added properties and methods to allow use of childrenAttributes e4bdd86
This page is out of date. Refresh to see the latest.
35  src/Symfony/Cmf/Bundle/MenuBundle/Document/MenuItem.php
@@ -58,6 +58,20 @@ class MenuItem implements NodeInterface {
58 58
      */
59 59
     protected $attributes;
60 60
 
  61
+    /**
  62
+     * Simulate a php hashmap in phpcr. This holds the keys.
  63
+     *
  64
+     * @PHPCRODM\String(multivalue=true)
  65
+     */
  66
+    protected $childrenAttributeKeys;
  67
+
  68
+    /**
  69
+     * Simulate a php hashmap in phpcr.
  70
+     *
  71
+     * @PHPCRODM\String(multivalue=true)
  72
+     */
  73
+    protected $childrenAttributes;
  74
+
61 75
     /** @PHPCRODM\Children(filter="*item") */
62 76
     protected $children;
63 77
 
@@ -166,6 +180,26 @@ public function setAttributes($attributes)
166 180
         $this->attributeKeys = array_keys($attributes);
167 181
     }
168 182
 
  183
+    public function getChildrenAttributes()
  184
+    {
  185
+        if (is_null($this->childrenAttributeKeys)) {
  186
+            return array();
  187
+        }
  188
+        $keys = $this->childrenAttributeKeys instanceof Collection ?
  189
+            $this->childrenAttributeKeys->toArray() :
  190
+            $this->childrenAttributeKeys;
  191
+        $values = $this->childrenAttributes instanceof Collection ?
  192
+            $this->childrenAttributes->toArray() :
  193
+            $this->childrenAttributes;
  194
+        return array_combine($keys, $values);
  195
+    }
  196
+
  197
+    public function setChildrenAttributes($attributes)
  198
+    {
  199
+        $this->childrenAttributes = $attributes;
  200
+        $this->childrenAttributeKeys = array_keys($attributes);
  201
+    }
  202
+
169 203
     public function getChildren()
170 204
     {
171 205
         return $this->children;
@@ -178,6 +212,7 @@ public function getOptions()
178 212
             'route' => $this->getRoute(),
179 213
             'label' => $this->getLabel(),
180 214
             'attributes' => $this->getAttributes(),
  215
+            'childrenAttributes' => $this->getChildrenAttributes(),            
181 216
             'display' => true,
182 217
             'displayChildren' => true,
183 218
             'content' => $this->getContent(),
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.