Comments

yongt9412 created an issue. See original summary.

johnchque’s picture

Status: Active » Needs review
StatusFileSize
new3.54 KB

Adding setting. :) Enabled by default.

Status: Needs review » Needs work

The last submitted patch, 2: add_setting_to_hide_duplicate-2946441-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new3.92 KB
new284 bytes

Adding schema. :)

johnchque’s picture

Rebased, tests added. :)

miro_dietiker’s picture

We discussed in the meta issue to determine how these settings should be stored and what exact settings.

The decision was to offer a single setting (also schema) to enable widget features. It should be a checkboxes element in UI.

Initially we want to have two features to enable / disable
- duplicate
- collapse all /expand all (one feature for both)

Right, exactly added with this issue here.

Best is you also create some getter to check of a feature is enabled for code simplicity.

And then there will be the third feature soon to enable/disable the „add before“ functionality.

johnchque’s picture

Adding tests, changing to what Miro addressed in the previous comment.

Status: Needs review » Needs work

The last submitted patch, 7: add_setting_to_hide_duplicate-2946441-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new10.35 KB
new651 bytes

This should work. :)

Status: Needs review » Needs work

The last submitted patch, 9: add_setting_to_hide_duplicate-2946441-9.patch, failed testing. View results

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new10.6 KB
new1.85 KB

Updating tests. :)

miro_dietiker’s picture

Status: Needs review » Needs work

This starts to look pretty nice. :-)

  1. +++ b/config/schema/paragraphs_type.schema.yml
    @@ -94,3 +94,8 @@ field.widget.settings.paragraphs:
    +      label: Available grid layouts
    

    :-) totally

  2. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -217,6 +218,15 @@ class ParagraphsWidget extends WidgetBase {
    +      '#title' => $this->t('Show widget features'),
    

    Enable, not show.

  3. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -265,6 +275,12 @@ class ParagraphsWidget extends WidgetBase {
    +          'multiple_actions' => $this->t('Collapse / Edit all'),
    

    That's a bad key. More edit-collapse-all

  4. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -490,20 +517,22 @@ class ParagraphsWidget extends WidgetBase {
    +        if ($this->isFeatureEnabled('duplicate')) {
    

    As this is a new functionality, we might need a second parameter for the default value if there is no feature setting data. Otherwise to keep the current two features enabled, we need a hook_update.

    @Berdir How to handle defaults?

  5. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -2528,4 +2557,27 @@ class ParagraphsWidget extends WidgetBase {
    +    foreach ($features as $key => $value) {
    

    I would guess there's aa much more compact solution in php, with array_search, _map, _filter

  6. +++ b/src/Tests/Experimental/ParagraphsExperimentalHeaderActionsTest.php
    @@ -119,6 +122,36 @@ class ParagraphsExperimentalHeaderActionsTest extends ParagraphsExperimentalTest
    +    // Disable show multiple actions.
    

    multiple => Collapse / Edit All

berdir’s picture

+++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
@@ -128,6 +128,7 @@ class ParagraphsWidget extends WidgetBase {
       'form_display_mode' => 'default',
       'default_paragraph_type' => '',
+      'features' => [],

One thing is that this key should explicitly list the default features that should be enough for the start.

It gets more complicated when we add additional features that should be enabled by default, e.g. by making more existing fuctionality configurable.

I guess it doesn't do recursive merge, so what we could do is have getFeatures() that explicitly returns $configured_features_list + ['some_key' => TRUE, 'other_key' => FALSE]

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new10.04 KB
new7.12 KB

I see, should be better now.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -217,6 +218,15 @@ class ParagraphsWidget extends WidgetBase {
    +      '#description' => $this->t('When creating a paragraph, whether to display widget actions or not. All features will be enabled if nothing is selected.'),
    

    The if nothing is selected part is wrong and should be removed. It's perfectly valid to disable all features, then nothing is enabled.

  2. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -300,6 +316,16 @@ class ParagraphsWidget extends WidgetBase {
    +    $features = $this->getSetting('features');
    +    $features_labels = [];
    +    foreach ($features as $id => $feature) {
    +      if ($feature) {
    +        $features_labels[] = $this->getSettingOptions('features')[$id];
    +      }
    

    you can use array_filter() to filter out the non-selected ones, and you should get the options once, not inside the loop.

    You could then even combine it with $feature_labels = array_intersect_key($this->getSettingOptions('features'), array_filter($this->getSetting('features'));

  3. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -490,20 +516,22 @@ class ParagraphsWidget extends WidgetBase {
    +        if ($this->isFeatureEnabled('duplicate')) {
    +          $widget_actions['dropdown_actions']['duplicate_button'] = [
    

    Question is whether this should be in access or not. Considering that we already have the duplicateButtonAccess() method, we could just put it in there?

  4. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -2338,7 +2366,7 @@ class ParagraphsWidget extends WidgetBase {
         // Collapse & expand all.
    -    if ($this->fieldDefinition->getType() == 'entity_reference_revisions' &&  $this->realItemCount > 1 && empty($field_state['dragdrop'])) {
    +    if ($this->fieldDefinition->getType() == 'entity_reference_revisions' &&  $this->realItemCount > 1 && empty($field_state['dragdrop']) && $this->isFeatureEnabled('collapse_edit_all')) {
           $collapse_all = $this->expandButton([
             '#type' => 'submit',
             '#value' => $this->t('Collapse all'),
    

    The dragdrop check is no longer needed, we don't go in there anymore when dragdrop is enabled.

  5. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -2528,4 +2556,22 @@ class ParagraphsWidget extends WidgetBase {
    +  protected function isFeatureEnabled($feature) {
    +    $features = $this->getSetting('features');
    +    $enabled = array_filter($features);
    +    if (in_array($feature, $enabled)) {
    +      return TRUE;
    +    }
    +    return FALSE;
    +  }
    

    You can simplify this to a if (!empty($features[$feature]), doesn't need the array_filter anymore then.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new8.59 KB
new3.98 KB

Yeah, that would be much better indeed, addressing changes. :)

miro_dietiker’s picture

Status: Needs review » Fixed

Yippie, committed. We have nice settings now.

Status: Fixed » Closed (fixed)

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