I tried making a YAML file with information taken from the Patterns Form Helper. Any help will be appreciated.

info:
  title: YAML example
  description: sample YAML pattern
  author: Vaish
  category: Examples
  author_email: vnd@graviteklabs.com

modules:
  - context
  - context_ui
  - text
  - taxonomy

actions:
  - tag: form
      module: context_ui
      form_id: context_ui_form
      system: 0
      value: homepage2
      attribute: section
      namespace: context_ui
      section: homepage2
      items:
          node:
            panel: 0
            blog: 0
            book: 0
            example: 0
            exercise: 0
            page: 0
            story: 0
            workout: 0
          user:
            2: 0
            4: 0
            3: 0
          book:
            book-toc-3: 0
          views:
            test_view: test_view
            date_browser: 0
            nodequeue_1: 0
          nodequeue:
            1: 0
          theme_section:
            title: 
            subtitle: 
            class: 
          theme_regiontoggle:
            left: 0
            right: 0
            content: 0
            header: 0
            footer: 0

Comments

qbnflaco’s picture

Here's the error I got.

Errors encountered during pre-processing:
Action #1 (form) in pattern YAML example: Couldn't load the form context_ui_form. Check if all required modules are enabled and try to define 'include_file' or 'module' tag for this action.

I even tried pointing to the .inc file and it still doesn't seem to work.

vaish’s picture

We introduced some changes to this particular functionality recently and that's why include_file didn't work for you. I'm going to update error message and docs to reflect the changes immediately.

"module" property that you defined in your pattern has limited power in finding the proper include file and it succeeds in most standard cases when include is called something like modulename.inc, modulename.admin.inc or modulename.page.inc. Context_ui module is using different naming convention "context_ui_admin.inc" so your pattern naturally failed.

Therefore it is recommended to use "include" property (previously called "include_file"). There are two ways of doing that:

  include:
    module: context_ui
    file: context_ui_admin.inc  #path to include file relative to modules directory
  include: full_drupal_path_to_include_file

First method is obviously better and strongly recommended.

Please note that "form" action has certain limitations and may not work for all the forms.
Some of the forms require additional parameters to be passed to the form function and currently there is no way to define those within the action.

For example this is a context_ui_form function:

  function context_ui_form(&$form_state, $op, $context = NULL) {
    ...

In this case $op and $context are additional parameters and $op seems to be required so my guess is your pattern may not work with this form.

We are planning to add support for parameters which will cover all the cases when additional params are simple data types that can be defined within the pattern.

ChrisBryant’s picture

Also, please note that our goal is to not have to list any specific includes so hopefully we'll have that handled soon where possible. Secondly Patterns should support as many key modules as possible so that tag: form rarely has to be used.

In cases like this, feel free to suggest or request additional support for specific modules such as context. We've been planning to have Patterns also set context (or also provide a similar method to define or register all of the Drupal entities that belong or relate to a specific pattern. Once we migrate the Patterns core to the Configuration Framework then it will be much easier to add support for other modules.

vaish’s picture

I just committed updates to form action that greatly improves support for more complex forms.

- "include" element is now not required anymore. Proper include file will be automatically discovered based on the menu router information
- additional parameters can be defined by using "args" element
- introduced "form_state_extras" for cases when form submit function depends on some particular value in $form_state array outside of $form_state['values']

This is how pattern should look now for context_ui_form:

  - tag: form
      form_id: context_ui_form
      args:
        - add
      form_state_extras:
        clicked_button:
          "#id": edit-submit
      system: 0
      value: homepage2
      attribute: section
      namespace: context_ui
      section: homepage2
      items:
          node:
            page: 0
            story: story
          user:
            2: 2
          theme_section:
            title: Section Title
            subtitle: Section Subtitle
            class: section-css
          theme_regiontoggle:
            left: left

#id needs to be wrapped in quotes because YAML uses # sign to mark comments.
The only way to determine "args" and "form_state_extras" is by looking at the code of form function itself as well as corresponding validate and submit functions.
In above example adding new contexts works fine. However, editing existing context would not work because form function expects as a third argument (second "args" element) complete context object which, at the moment, cannot be defined in the YAML file.

ChrisBryant’s picture

Thanks Vaish! can you update the documentation (http://drupal.org/node/408960) to remove the info about the include files?

vaish’s picture

I updated docs at the same time when this feature was added. I didn't remove mention of includes completely because that is still valid syntax and it should be documented. However, example code is not using it anymore and description is updated accordingly. Please check it out and suggest any changes and improvements you find appropriate.

vaish’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.