Patterns and reusable blocks are now merged. This allows for the user to save patterns (synced or unsynced). Also, reusable blocks are now called synced patterns.

Use wp_pattern_sync_status property to distinguish types (API endpoint - /v2/blocks).
wp_pattern_sync_status = '' - synced
wp_pattern_sync_status = 'unsynced' - unsynced

In addition to the content block type that is created, a vocabulary (Pattern Category) needs to be created and add a taxonomy reference to Reusable block type.
Add Sync Status field to Reusable block type.

Pattern Category terms can be created when saving patterns.

Add wp_pattern_category (array of taxonomy ids) to API endpoints.

Issue fork gutenberg-3402975

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

marcofernandes created an issue. See original summary.

  • marcofernandes committed 933f65b9 on 3402975-update-patterns
    Issue #3402975 by marcofernandes: Adjust patterns view
    

  • marcofernandes committed 9e63da65 on 3402975-update-patterns
    Issue #3402975 by marcofernandes: Remove some attributes that caused...

  • marcofernandes committed f377afc2 on 3402975-update-patterns
    Issue #3402975 by marcofernandes: Refactor code to ES6 + add missing...

  • marcofernandes committed 0376b6a7 on 3402975-update-patterns
    Issue #3402975 by marcofernandes: Add dependencies; remove CI for...

  • marcofernandes committed 0031078a on 3402975-update-patterns
    Issue #3402975 by marcofernandes: Validate array key; Remove Bartik and...

  • marcofernandes committed 0031078a on 3.0.x
    Issue #3402975 by marcofernandes: Validate array key; Remove Bartik and...

  • marcofernandes committed 0376b6a7 on 3.0.x
    Issue #3402975 by marcofernandes: Add dependencies; remove CI for...

  • marcofernandes committed f377afc2 on 3.0.x
    Issue #3402975 by marcofernandes: Refactor code to ES6 + add missing...

  • marcofernandes committed 9e63da65 on 3.0.x
    Issue #3402975 by marcofernandes: Remove some attributes that caused...

  • marcofernandes committed e3f42591 on 3.0.x
    Issue #3402975 by marcofernandes: Patterns and synced patterns (reusable...
marcofernandes’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

codebymikey’s picture

Priority: Normal » Major
Status: Closed (fixed) » Needs work

There's no update hook for the new reusable block field_pattern_category and field_pattern_sync_status fields introduced here. This breaks on a site upgrading from 2.x whenever you attempt to add a new pattern:

The website encountered an unexpected error. Please try again later.<br><br><em class="placeholder">InvalidArgumentException</em>: Field field_pattern_category is unknown. in <em class="placeholder">Drupal\Core\Entity\ContentEntityBase->getTranslatedField()</em> (line <em class="placeholder">587</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/ContentEntityBase.php</em>). <pre class="backtrace">Drupal\Core\Entity\ContentEntityBase->get('field_pattern_category') (Line: 323)
Drupal\gutenberg\Controller\ReusableBlocksController->getBlockAttributes(Object) (Line: 229)
Drupal\gutenberg\Controller\ReusableBlocksController->save(Object, NULL)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 692)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
</pre>

An upgrade path should be created or documented. Ideally something in an update hook.

I think there might also be an issue with the autosave API path /wp/v2/pages/-1/autosaves no longer being matched by the /\/wp\/v2\/(.*)\/autosaves\?(.*)/g regex when trying to update an existing API path.

I think we should probably add a console.warn() call in the api-fetch before returning the "API handler not found" promise, just so it's easier to easily any missing/breaking REST API implementations in future releases.

marcofernandes’s picture

Status: Needs work » Needs review
codebymikey’s picture

Sorry it took a while to get back to this. I like the approach, but it seems like \Drupal::service('config.installer')->installDefaultConfig('module', 'gutenberg') will override any local configuration overrides the sites might have, so we need special handling for it.

I've pushed an update to the branch with the updated logic, feel free to test and review, and let me know if it all makes sense.

marcofernandes’s picture

I tested from a clean Drupal instance, installed Gutenberg 2.x, enabled Gutenberg for Basic Page changed Gutenberg text format a bit just to check if configuration wouldn't be override. Then I updated Gutenberg to this branch and did an update db but it threw this error:

  Unable to decode output into JSON: Syntax error                                          

  TypeError: Drupal\Core\Field\WidgetBase::__construct(): Argument #5 ($third_party_setti  
  ngs) must be of type array, null given, called in /var/www/html/web/core/lib/Drupal/Cor  
  e/Field/WidgetBase.php on line 64 in Drupal\Core\Field\WidgetBase->__construct() (line   
  53 of /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php).                      

Ran update db again but at this time no error occurred and configuration seemed to be ok. At least no override on the text format settings and fields were created.

  • marcofernandes committed 32d0946b on 3.x
    Issue #3402975 by marcofernandes, codebymikey: Add update hook to...

  • marcofernandes committed eeb52ce9 on 3.x
    Issue #3402975 by marcofernandes, codebymikey: Add third_party_settings...

  • codebymikey committed ff5e6595 on 3.x
    Issue #3402975: Add Patterns and synced patterns (reusable blocks) post...

marcofernandes’s picture

Status: Needs review » Fixed
marcofernandes’s picture

  • marcofernandes committed 32d0946b on 3.0.x
    Issue #3402975 by marcofernandes, codebymikey: Add update hook to...

  • marcofernandes committed eeb52ce9 on 3.0.x
    Issue #3402975 by marcofernandes, codebymikey: Add third_party_settings...

  • codebymikey committed ff5e6595 on 3.0.x
    Issue #3402975: Add Patterns and synced patterns (reusable blocks) post...

  • marcofernandes committed 70d61827 on 3.0.x
    Issue #3402975: Update existing reusable blocks sync status field
    

Status: Fixed » Closed (fixed)

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