Skip to content

Instantly share code, notes, and snippets.

@AlexSkrypnyk
Last active July 3, 2017 08:14
Show Gist options
  • Save AlexSkrypnyk/e5d596eb7ef23bec182d055edfbc2ba8 to your computer and use it in GitHub Desktop.
Save AlexSkrypnyk/e5d596eb7ef23bec182d055edfbc2ba8 to your computer and use it in GitHub Desktop.
Page builder paragraphs authoring

The implementation of step definitions for paragraphs authoring is based on the sharing of the state of the most recently created content item.

There are 2 important pieces:

  1. Current host entity stack - tracks all entities through step definitions.
  2. Host entity lookup by current bundle and a field name - allows to traverse through host entity stack to find the first fitting candidate for currently added paragraphs item.

Step definition

Step definition can be used in 2 syntaxes:

  • And I add <bundle> paragraph to <host_field_name>
  • And I add <bundle> paragraph to <host_field_name> with fields: <TableNode>

where

  • <bundle> - paragraph_item bundle of the currently added paragraphs_item.
  • <host_field_name> - field name of the host entity that should accept the currently added paragraphs_item.
  • <TableNode> - table of field names and their values for the currently added paragraphs_item.

The definition will do the following:

  • Validate that current host entity is set (by default, host entity is a last created entity)
  • Validate that provided field exists on the entity and can accept a bundle of current paragraphs_item.
    • If validation fails - move up in the stack of host entity types and try to resolve with a parent.
      • If an valid host entity item is found in the stack - set this item as current parent host entity and proceed below.
      • If a valid host entity is not found - throw an exception notifying developer that steps in scenario are not in the expected order.
  • Create an instance of the bundle.
  • If fields for currently created paragraphs_item were provided - pupulate them.
  • Save host entity (also, need to make sure that this process saves the node itself).
Scenario: Page builder paragraphs authoring
Given I create a published 'page_builder' with content:
| title | Example page |
| field_theme | victory |
# Create section with title.
And I add Section paragraph to 'field_page_builder_section' with fields:
| title | Section 1 |
And I add WYSIWYG paragraph to 'field_left' with fields:
| body | W1 body |
And I add Video paragraph to 'field_left' with fields:
| fid | 123 |
# Add accordion with 2 Accordion Items.
And I add Accordion paragraph to 'field_left'
And I add Accordion Item paragraph to 'field_acordion_items' with fields:
| field_body | A1v1 |
And I add Accordion Item paragraph to 'field_acordion_items' with fields:
| field_body | A2v2 |
# Add another accordion with 2 Accordion Items.
And I add Accordion paragraph to 'field_left'
And I add Accordion Item paragraph o 'field_acordion_items' with fields:
| field_body | A1v1 |
And I add Accordion Item paragraph to 'field_acordion_items' with fields:
| field_body | A2v2 |
# Create another section with title.
And I add Section paragraph to 'field_page_builder_section' with fields:
| title | Section 2 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment