Problem:
If i have a layout with 2 columns, i can only restrict paragraphs for the whole layout. If a paragraph is only suitable for the left column, I can't restrict the editor to only allow the paragraph in the left column.

Proposed resolution:
Additionally to restrict paragraphs per layout, it is also possible to define for each column which paragraphs are allowed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

InaW created an issue. See original summary.

dermario’s picture

Title: Restrict paragraphs per column » Restrict paragraphs per section
Priority: Normal » Critical

Marking this as critical, as this is the main purpose of this module.

InaW’s picture

Assigned: InaW » Unassigned
saschaeggi’s picture

Huge +1

waluigi’s picture

Title: Restrict paragraphs per section » Restrict paragraphs per region
FileSize
9.4 KB

Thanks for the suggestion, that totally makes sense to me as well. I created a patch for this, I'd appreciate any testing :-)

saschaeggi’s picture

@waluigi applied the patch and did some testing
Looks good so far, but when I want to add a paragraph it doesn't show up at all.
Also I think #3087079: Allow all paragraph types if none are selected is important as well.

saschaeggi’s picture

Also we might want to make sure that it still works with this patch from entity_reference_layout #3070005-11: Implement a nicer solution to element selection applied.

waluigi’s picture

Thanks for the feedback, @saschaeggi.

The problem was that they were moved to "disabled items" directly because it did not fetch the allowed paragraphs correctly for the target region. Also one could not drag and drop it into other regions for the same reason. I was not yet able to fix the whole problem, however the drag and drop is working now.

Newly added paragraphs will still be appended to the disabled items wrapper. I'm still working on a solution for that.

waluigi’s picture

I was able to fix it. The problem was a reference to a wrong parent.
Thanks for any feedback!

waluigi’s picture

Status: Active » Needs review
dermario’s picture

Status: Needs review » Needs work

I reviewed the PHP part of this patch and it looks awesome already. These are my findings:

  1. +++ b/src/Plugin/Field/FieldWidget/ErlRestrictionWidget.php
    @@ -36,40 +36,44 @@ class ErlRestrictionWidget extends EntityReferenceLayoutWidget implements Contai
    -         foreach ($this->getSettings()['restrictions'][$layout] as $layout => $value){
    -           if ($value !== 0){
    ...
    +        foreach ($this->getSettings()['restrictions'][$layout][$region_key] as $value_key => $value) {
    

    I wonder if we could store $this->getSettings()['restrictions'][$layout] in a variable to make the following code more readable/meaningful.

  2. +++ b/src/Plugin/Field/FieldWidget/ErlRestrictionWidget.php
    @@ -90,10 +94,11 @@ class ErlRestrictionWidget extends EntityReferenceLayoutWidget implements Contai
    +    $form = parent::settingsForm($form, $form_state); // TODO: Change the autogenerated stub
    

    This comment is obsolete.

  3. +++ b/src/Plugin/Field/FieldWidget/ErlRestrictionWidget.php
    @@ -90,10 +94,11 @@ class ErlRestrictionWidget extends EntityReferenceLayoutWidget implements Contai
    +    $entity_manager = \Drupal::service('entity.manager');
    

    I think entity.manager gets deprecated in D9 we should avoid using it.

    The new service should use dependency injection in favor of creating the service on the fly.

waluigi’s picture

Thanks for the feedback @dermario. I implemented your suggestions. What do you think now?

waluigi’s picture

Since my codesniffer is currently not working properly I missed some spaces. Here is the new patch.

dermario’s picture

Status: Needs work » Reviewed & tested by the community

This looks fine for me now. We could fix these while committing the patch.

+++ b/src/Plugin/Field/FieldWidget/ErlRestrictionWidget.php
@@ -103,21 +109,31 @@ class ErlRestrictionWidget extends EntityReferenceLayoutWidget implements Contai
+          $default = "";

This could be single quotes for consistency reasons.

  • waluigi committed 52aff57 on 8.x-1.x
    Issue #3087094 by waluigi, InaW, dermario, saschaeggi: Restrict...
waluigi’s picture

Status: Reviewed & tested by the community » Fixed

Thanks to all for the support! :)

waluigi’s picture

Status: Fixed » Closed (fixed)