Hey,

the module paragraphs previewer (https://www.drupal.org/project/paragraphs_previewer) provides a nice functionality to preview paragraphs using the frontend theme.
I think it would be a nice feature if other modules could extend the form widgets to add completely new options to them. A example could be that the paragraphs previewer module adds a checkbox to the Experimental form widget to enable the previewer functions.

What do you think?

Greetings
Sebastian

Concept:
Concept is taken and overhauled based on: Link

Extending Paragraph Form Widgets

Current State
When a 3rd party module currently wants to extend the Paragraphs form widget, it has to extend one of the classes “InlineParagraphsWidget” (Paragraphs Classic) or “ParagraphsWidget" (Paragraphs EXPERIMENTAL).
This is bad since this does prevent us from using 3rd Party modules in combination, like for example:

Paragraphs Previewer
https://www.drupal.org/project/paragraphs_previewer

and

Paragraphs Browser
https://www.drupal.org/project/paragraphs_browser

Both modules provide a own form widget for Paragraphs.

Development to be done
We need to provide a hook that allows 3rd Party modules to extend the existing Paragraph form widgets. The following tasks has to be implemented.

Extending existent options
The Paragraphs form widget already provides a lot of functionalities, like for example having different options of adding paragraphs. (Buttons, Select List, Drop Down)

The hook has to allow us to extend options like this. This will allow others modules like for example Paragraphs Browser to add them selfs as a “Add Mode” within the default Paragraphs Form Widget.

Add new options
Additionally the hook has to give us the possibility to add completely new options to the Paragraphs form widget. For example the module Paragraphs Previewer gives us a great option to have a “Preview” of our paragraphs using the frontend themes CSS and JS.
To get it actually working with the Paragraph default form widgets, we would need the possibility to add a new option to those, something like e.g. “Activate Paragraph Preview”.

Widgets
The Paragraph modules itself provides two Form Widgets: "Paragraphs Classic” & "Paragraphs EXPERIMENTAL”. The hook has to allow us to add/extend options for the "Paragraphs EXPERIMENTAL" form widget, since the "Paragraphs Classic” form widget will be deprecated somewhen in the future.
Updated based on: Link

Cleanup
The current configuration options are deeply nested within the paragraphs module code. Those configuration options needs to be adjusted to be more “stand alone”.
Extension from miro_dietiker:
"My proposal was also, if we manage to make the add mode extensible, it would be interesting to consider outsourcing the different current add modes into separate files.. The widget code might be much more compact."

Module Tests
The Paragraph module is very well maintained and is heavily test orientated. To get the patch added to dev branch by the maintainers (Berdir & miro_dietiker), we must provide test cases within the module.
"The test module should implement the hooks to provide a common example use cases of a new add mode." - miro_dietiker

To be done before the development starts:
Before the actual development start, we have to write a technical concept that outlines the new APIs. The API concept as has to be approved by the maintainer of the paragraphs module. Comment

Comments

sgurlt created an issue. See original summary.

miro_dietiker’s picture

Status: Active » Postponed (maintainer needs more info)
sgurlt’s picture

#2868155: Add new hooks to allow easier editing of paragraph forms

This looks very promissing and I will give it a closer look.
The second issue was opened up also by myself and it was nearly the same, but with this issue here i wanted to add complete new options the other issue was just about extend existing options. I think both might be possible by using the hooks described within: #2868155: Add new hooks to allow easier editing of paragraph forms.

I will update the issues after further investigation.

sgurlt’s picture

Update:

Hmm not a 100% sure that the patch provided in the issue will resolve this for me: https://www.drupal.org/node/2868155#comment-12239068

sgurlt’s picture

Status: Postponed (maintainer needs more info) » Needs review

Extending Paragraph Form Widgets

Current State
When a 3rd party module currently wants to extend the Paragraphs form widget, it has to extend one of the classes “InlineParagraphsWidget” (Paragraphs Classic) or “ParagraphsWidget" (Paragraphs EXPERIMENTAL).
This is bad since this does prevent us from using 3rd Party modules in combination, like for example:

Paragraphs Previewer
https://www.drupal.org/project/paragraphs_previewer

and

Paragraphs Browser
https://www.drupal.org/project/paragraphs_browser

Both modules provide a own form widget for Paragraphs.

Development to be done
We need to provide a hook that allows 3rd Party modules to extend the existing Paragraph form widgets. The following tasks has to be implemented.

Extending existent options
The Paragraphs form widget already provides a lot of functionalities, like for example having different options of adding paragraphs. (Buttons, Select List, Drop Down)

The hook has to allow us to extend options like this. This will allow others modules like for example Paragraphs Browser to add them selfs as a “Add Mode” within the default Paragraphs Form Widget.

Add new options
Additionally the hook has to give us the possibility to add completely new options to the Paragraphs form widget. For example the module Paragraphs Previewer gives us a great option to have a “Preview” of our paragraphs using the frontend themes CSS and JS.
To get it actually working with the Paragraph default form widgets, we would need the possibility to add a new option to those, something like e.g. “Activate Paragraph Preview”.

Widgets
The Paragraph modules itself provides two Form Widgets: "Paragraphs Classic” & "Paragraphs EXPERIMENTAL”. The hook has to allow us to add the option to either both form widgets, or by a specified one.

Cleanup
The current configuration options are deeply nested within the paragraphs module code. Those configuration options needs to be adjusted to be more “stand alone”.

Module Tests
The Paragraph module is very well maintained and is heavily test orientated. To get the patch added to dev branch by the maintainers (Berdir & Miro_dietiker), we must provide test cases within the module.

miro_dietiker’s picture

Status: Needs review » Active

I'm only maintaining new features like this inside the new experimental widget.
The other Classic should change as few as possible and will likely be deprecated at some point.

I agree about what you describe, but we first should outline the new APIs we need to cover these use cases before implementing.
Or you jump into implementing the hooks with a prototype... without any guarantee yet if we are happy with what we learn.

The test module should implement the hooks to provide a common example use cases of a new add mode.

My proposal was also, if we manage to make the add mode extensible, it would be interesting to consider outsourcing the different current add modes into separate files.. The widget code might be much more compact.

Please move the poposal into the issue summary. Chances are you want to promote this issue to a META issue. This means code / patches only in child issues.

sgurlt’s picture

Issue summary: View changes
sgurlt’s picture

Issue summary: View changes
sgurlt’s picture

I have updated the concept within the main issue description considering your thoughts and adjustments. About:

I agree about what you describe, but we first should outline the new APIs we need to cover these use cases before implementing.
Or you jump into implementing the hooks with a prototype... without any guarantee yet if we are happy with what we learn.

I will give this to our development team and they will have to provide a concept for it.

sgurlt’s picture

Issue summary: View changes
sgurlt’s picture

Issue summary: View changes
sgurlt’s picture

Issue summary: View changes
sgurlt’s picture

Version: 8.x-1.1 » 8.x-1.x-dev
Priority: Normal » Major
Status: Active » Needs review

I have tried to reach Berdir (https://www.drupal.org/u/berdir) and Miro (https://www.drupal.org/u/miro_dietiker) but both have not responded to my mails for a long time now. Is here a Maintainer that will have a look on a concept that we have created (will be send via Mail) according to the above described task?

miro_dietiker’s picture

There are no other active Maintainers of the 8.x branch.

We have spent a lot of time to refactor the widget and remove complexity. Yet some complexity grew again by new functionality.

Our time is very limited as long as direct funding of our Paragraph work is on the current minimal level.
I appreciate any type of contribution. There are two problems though:
* First, we spent more than 2 weeks of work in 2017 to talk to potential contributors that then didn't contribute.
* Proposals like this are adding complexity we then need to maintain. Thus it adds work in the short term to review, communicate and in the long term.

There would be a simple solution: If you want to provide incentive for us to work on your priorities, you could help us to resolve major / critical issues in Paragraphs.

I re-read the proposal above and it's still hard to answer.
The mail you wrote proposed two approaches. I'm not sure about both.

In many cases, we need to prototype proposals to understand if they are the right direction.

First, there is already an extension point for per-paragraph operations. We use this heavily, but it's limited to the "..." button. We want to be very careful with adding too many extension points as hooks can add messi spaghetti-like code sequences... We intentionally started to drop settings that don't provide value anymore to straighten the code.

It looks like we will add Paragraph hooks so every relevant aspect of the widget is easy to alter:
#2868155: Add paragraph bundle to widget forms to allow easier editing of paragraph forms
The hooks are not yet completely defined, but it looks like a plugin system dedicated to the add mode only seems obsolete.
These hooks are needed anyway, so please help us providing example use cases and implement test coverage there.

We spent iterating on the experimental widget for about a year now. Thunder is starting to adapt it as well and we wanted to stabilise it.
We tried multiple approaches to further separate it, but it led to growing complexity and indirection. We picked specific improvements of these iterations, but dropped the idea of splitting the widget further.

I'm still open to further architectural changes if they are a major architectural improvement. The conditions for an acceptable situation would be:
* The code complexity doesn't grow with artificial constructions
* Current code that covers multiple cases are split into separate plugins
* I can still follow the widget lifecycle and an edit + add + save process easily.

But i doubt that this is possible. In fact, working on drag & drop and other improvements during the past months showed us that the key complexity originates in architectural design and limitations of the (Drupal 8 core) widget lifecycle combined with the form lifecycle. Their architecture requires workarounds that are hard to abstract away, leading to repeated complexity for every code interfering with a Paragraph widget lifecycle. Every Plugin or sub-plugin would be hit by it.

So while i'm interested in prototyping the separation: If all Paragraph modes are plugins, what's the purpose of the Paragraph widget itself? It seems to me then every of these specific widgets could simply be regular standalone widgets. We could still move some parts into Traits or so to avoid too much code duplication, or a Widget base.

That said, if these learnings are not mind blowing, chances are that we would need to offer such a solution as a third newer modular widget and stabilize the current experimental one like it is now.

miro_dietiker’s picture

Status: Needs review » Active
sgurlt’s picture

Hey Miro,

thanks for the input. We got your points and we're currently in clarification how we will proceed. At the moment we are having a look at the hooks which are included within: https://www.drupal.org/project/paragraphs/issues/2868155, if they are enough for what we already want to achieve and if we need more of them. In addition we are planning to provide tests for the hooks we are added by the previous mentioned issue.

Greetings
Sebastian

miro_dietiker’s picture

Great @sgurlt, we're looking forward to updates. :-)