By chance, I found what appears to be the XML syntax for sub-patterns here. Something like:

<!-- execute pattern "news" -->
<pattern>news</pattern>

I'm trying to write my patterns in YAML however, and am having trouble figuring out what the proper syntax should be.

Looking in the documentation, I don't see any info on how to implement sub-patterns.

I've referenced the module packaged documentation, and these online pages:
http://drupal.org/node/346509
http://drupal.org/node/408940

Comments

shakty’s picture

Hi,
unfortunately, in the 7.x branch sub-patterns are disabled for now.

The documentation you are referring to, is for Patterns 6.x, and there are a few changes introduced with the 7.x version. Please refer to the doc folder inside the patterns module directory. That should be enough, but if that is not clear you can just ask here.

Here is an example for a YAML pattern.

# This is a comment
# Example Pattern

info: # mandatory name
  title: New Vocabulary
  description: Adds a new vocabulary to the website
  author: QScience
  category: Examples
  version: 1.0
  core: 7.x
  author_email: email@mail.com
  author_website: qlectives.eu

actions: # any name is good for this category

  - create:
        tag: vocabulary
        name: Another Vocabulary
        machine_name: anothervoc
        description: Another interesting vocabulary
        hierarchy: 0

  - modify:
        tag: vocabulary
        machine_name: anothervoc
        description: It was not that interesting after all
        # vid: 2

  - delete:
        tag: vocabulary
        machine_name: anothervoc
        # vid: 2
davidcsonka’s picture

Thanks! I'm learning the YAML syntax pretty well, was just wondering specifically about the sub-patterns. I see that you say it is disabled in the current version of Patterns 7.x

Could you provide an example of how it would look though? Thanks

davidcsonka’s picture

Are relation and parent attributes for taxonomy terms allowed in the current 7.x branch of Patterns?

I can't get those to work either, nor can I find examples of the proper syntax for utilizing the parent or relations attributes in a Pattern YAML file.

The Taxonomy Syntax documentation here (http://drupal.org/node/408954) doesn't provide any examples. There are no examples provided in the packaged module documentation either.

So, I guess that begs a more important questions. Is there a need for help to expand/update the documentation for Patterns?

As somebody who is new to the module, but desperately wants to make use of it - I can see a need.

shakty’s picture

Hi davidcsonka,

many questions, here are some answers:

- we haven't fixed the syntax for sub-patterns yet. We were concentrating on other issues first. You could propose a syntax which looks intuitive for the users, we would be happy to discuss it.

- as for parent attributes for taxonomy terms, they should work, I am going to double check them and let you know.

- and I think yes, definitely we need better documentation! Again any help, suggestion, critique is very welcome.

Cheers.

shakty’s picture

All right, I just pushed a fix for the using parent relationships in taxonomy terms. That should work.

Just get the latest code from git with this command:

git clone --branch 7.x-1.x http://git.drupal.org/project/patterns.git

Here an example how to use it:

# pattern info 

actions:

    - create:
        tag: term
        name: Term with parent
        descr: I have a parent 
        vocabulary: tags # machine_name
        parent: 
                - 1 # numerical id from the database
                - father # tag name: works only if there are no duplicates

# or

    - create:
        tag: term
        name: Term with parent
        descr: I have a parent 
        vocabulary: tags # machine_name
        parent: 1

# or

    - create:
        tag: term
        name: Term with parent
        descr: I have a parent 
        vocabulary: tags # machine_name
        parent: father
shakty’s picture

Status: Active » Fixed
davidcsonka’s picture

Thank you for the info. In regard to documentation, I will see if I can help out by updating those older documentation pages on drupal.org with syntax examples, as I learn them.

Regarding parent terms, and your fix. I pulled down the new version and installed it. However, it doesn't seem to work, and I get an error.

I used this pattern:

# YAML Parent Taxonomy Terms Test Pattern

info:
  title: Parent Taxonomy Terms Test
  description: Adds taxonomy terms to the tags vocabulary.
  author: David Csonka
  category: Taxonomy
  version: 1.0
  core: 7.x
  
# Taxonomy Vocabularies
# VID - Machine Name
# 1 - tags
# 2 - forums

actions:

    - create:
        tag: term
        name: Parent
        descr: This is a parent term.
        vocabulary: tags # machine_name

    - create:
        tag: term
        name: Child
        descr: This is a child term.
        vocabulary: tags # machine_name	
		parent: Parent

It produced the two terms when run, but the child term does not get the "Parent" term set as it's parent. No relation is created.

Also, I get this error when going back and forth from the Pattern edit screen, when verifying that the pattern is valid.

TYPE php
DATE Friday, February 10, 2012 - 10:24
USER admin
LOCATION http://localhost/admin/patterns
REFERRER http://localhost/batch?op=start&id=7
MESSAGE Warning: Invalid argument supplied for foreach() in _patterns_scan_pattern() (line 338 of C:\xampp\htdocs\sites\all\modules\patterns\includes\patterns.parser.inc).
SEVERITY warning
HOSTNAME 127.0.0.1

davidcsonka’s picture

Also, does this new dev version require the module: Macro?

7.x-1.x-dev Enables extremely simple adding/removing features to your site with minimal to no configuration.
Requires: Token (enabled), Libraries (enabled), Macro (missing)

This seems changed from the previous version, and Macro isn't even developed for Drupal 7.

shakty’s picture

Status: Fixed » Active

Hi,

actually, there is a version of Macro for Drupal 7...I know because I pushed it there. It does not show up on the main page, because it is still experimental, but you can download it with git or from here:

http://drupal.org/node/430278/release

or with drush.

Please tell me if after installing macro you still get the error, and I will look into that.

Thanks for the precious help!

davidcsonka’s picture

Ok, I installed that version of Macro and the modules interface didn't indicate there were any problems. However, when I have that test YAML pattern in the patterns dir, I still get that ForEach error. Slightly different though, because the referrer mentions modules, rather than batch.

TYPE php
DATE Friday, February 10, 2012 - 15:17
USER admin
LOCATION http://localhost/admin/patterns
REFERRER http://localhost/admin/modules
MESSAGE Warning: Invalid argument supplied for foreach() in _patterns_scan_pattern() (line 338 of C:\xampp\htdocs\sites\all\modules\patterns\includes\patterns.parser.inc).
SEVERITY warning
HOSTNAME 127.0.0.1

If I remove all the other patterns from the dir and just put this one instead:

# YAML Set Default Theme Pattern

info:
  title: Set Default Theme
  description: Sets the default theme.
  author: David Csonka
  category: Theme
  version: 1.0
  core: 7.x

actions:

    - create:
        tag: theme
        value: cti_flex

It doesn't throw any errors.

shakty’s picture

Hi,

sorry for coming back to you so late. I actually can't reproduce your warning.

Do you get it with the standard files which are included in the pattern module, or did u already write some custom ones? If so, it would be very interesting to know which files is creating the error.

Besides this warning, are parent relantionships working for you now ? They are, on my environment.

Let me know!

davidcsonka’s picture

The standard sample files which come with the Pattern Module do not provide examples of adding parent terms, or sub-patterns. Otherwise, I probably wouldn't have needed to post my questions here. :D It would be nice if the module shipped with example encoded files for these types. I can find no documentation *anywhere* explaining how to do those things.

Anyway,
I don't get the "forEach" error when running most of my pattern files, that validate fine.

I mainly get the error when trying to run this custom pattern:

# YAML Parent Taxonomy Terms Test Pattern

info:
  title: Parent Taxonomy Terms Test
  description: Adds taxonomy terms to the tags vocabulary.
  author: David Csonka
  category: Taxonomy
  version: 1.0
  core: 7.x
  
# Taxonomy Vocabularies
# VID - Machine Name
# 1 - tags
# 2 - forums

actions:

    - create:
        tag: term
        name: Parent
        descr: This is a parent term.
        vocabulary: tags # machine_name

    - create:
        tag: term
        name: Child
        descr: This is a child term.
        vocabulary: tags # machine_name	
	parent: Parent

It' just a small sample encoding to try and test the syntax which you explained to me for adding parent terms. It validates, but when I run it - it does *not* set the parent relation.

shakty’s picture

Hi,

I just pushed a fix which should finally make your pattern work.

# YAML Parent Taxonomy Terms Test Pattern

info:
  title: Parent Taxonomy Terms Test 15
  description: Adds taxonomy terms to the tags vocabulary.
  author: David Csonka
  category: Taxonomy
  version: 1.0
  core: 7.x
 
# Taxonomy Vocabularies
# VID - Machine Name
# 1 - tags
# 2 - forums

actions:

    - create:
        tag: term
        name: Parent15
        descr: This is a parent term.
        vocabulary: tags # machine_name
        
    - create:
        tag: term
        name: Child15
        descr: This is a child term.
        vocabulary: tags # machine_name
        parent: Parent15

Regarding the foreach issue, the problem is that the yaml file you pasted here is malformed. In fact the separator in the last line is a big tab instead of spaces, as it is before. It is actually strange that you could save / import that file. I will investigate this issue later on.

Please tell me if the parent relantionships are now correctly set.

Cheers.

davidcsonka’s picture

That's pretty obnoxious that YAML is such a stickler for that kind of syntax! It seems to me that XML would be easier to use, but there were less examples provided in the XML format, so I didn't have much choice.

Thanks for working on this and teasing out the problem with me. I plan to utilize Patterns a great deal for my site migration/staging efforts, it's a such a great concept.

I will need to wait for the patch to be merged before I can download the new deb branch?

shakty’s picture

You can download it from git. If that works, I close this issue.

csko’s picture

Status: Active » Needs review

I've added the dev branch to the releases as well as created a tag for the latest version. Both contain these changes mentioned here.

davidcsonka’s picture

This worked, thanks! Also, thank you for the insight into the error cause, being the issue with tabs vs. spaces. I didn't realize YAML was so specific.

shakty’s picture

Status: Needs review » Closed (fixed)