vaersaagod / matrixmate

Welding Matrix into shape, mate!
MIT License
44 stars 9 forks source link

Bug - hiddenTypes - doesn't work when groups added #49

Closed CreateSean closed 2 years ago

CreateSean commented 2 years ago

Craft 4.0.3 MatrixMate 2.0.1

Using this config with groups commented out the hiddenTypes in the fragments section works as expected.

<?php

return [
  'fields' => [
    // content builder
    'contentBuilder' => [
      // 'defaultTabName' => 'Additional Settings',
      // 'groups' => [
      //   [
      //     'label' => 'Text Heavy',
      //     'types' => ['copy'],
      //   ],
      // ],

      // hide fragments block from fragment channel
      'section:fragments' => [
        'hiddenTypes' => ['fragments'],
      ],
    ],
  ],
];

However when I uncomment the groups groups works as expected and the fragment is now visible

<?php

return [
  'fields' => [
    // content builder
    'contentBuilder' => [
      // 'defaultTabName' => 'Additional Settings',
      'groups' => [
        [
          'label' => 'Text Heavy',
          'types' => ['copy'],
        ],
      ],

      // hide fragments block from fragment channel
      'section:fragments' => [
        'hiddenTypes' => ['fragments'],
      ],
    ],
  ],
];
mmikkel commented 2 years ago

You're using the wrong syntax for the config contexts, which confuses MatrixMate. It should probably look like this:

<?php

return [
    'fields' => [
        // content builder
        'contentBuilder' => [
            '*' => [
                // 'defaultTabName' => 'Additional Settings',
                'groups' => [
                    [
                        'label' => 'Text Heavy',
                        'types' => ['copy'],
                    ],
                ],
            ],
            // hide fragments block from fragment channel
            'section:fragments' => [
                // 'defaultTabName' => 'Additional Settings',
                'groups' => [
                    [
                        'label' => 'Text Heavy',
                        'types' => ['copy'],
                    ],
                ],
                'hiddenTypes' => ['fragments'],
            ],
        ],
    ],
];
CreateSean commented 2 years ago

That still doesn't work.

Here is what I have with the wildcard for the groups

<?php

return [
    'fields' => [
        // content builder
        'contentBuilder' => [
            '*' => [
                // 'defaultTabName' => 'Additional Settings',
                'groups' => [
                  [
                    'label' => 'Text Heavy',
                    'types' => ['copy', 'blockquote','testimonials', 'doubleColumnWithBackground'],
                  ],
                  [
                    'label' => 'Imagery',
                    'types' => ['imageCopy','fullWidthImage', 'squareCards', 'credentials'],
                  ],
                  [
                    'label' => 'Other',
                    'types' => ['fragment', 'callToAction', 'featuredProjects', 'press', 'contactCards', 'team', 'addForm'],
                  ],
                ],
            ],
            // hide fragments block from fragment channel
            'section:fragments' => [
                'hiddenTypes' => ['fragments'],
            ],
        ],
    ],
];

This does not hide the fragments in the fragments channel and is not using the groups from the wildcard.

If I copy the groups from the wildcard into the section:fragments

<?php

return [
    'fields' => [
        // content builder
        'contentBuilder' => [
            '*' => [
                // 'defaultTabName' => 'Additional Settings',
                'groups' => [
                  [
                    'label' => 'Text Heavy',
                    'types' => ['copy', 'blockquote','testimonials', 'doubleColumnWithBackground'],
                  ],
                  [
                    'label' => 'Imagery',
                    'types' => ['imageCopy','fullWidthImage', 'squareCards', 'credentials'],
                  ],
                  [
                    'label' => 'Other',
                    'types' => ['fragment', 'callToAction', 'featuredProjects', 'press', 'contactCards', 'team', 'addForm'],
                  ],
                ],
            ],
            // hide fragments block from fragment channel
            'section:fragments' => [
                'hiddenTypes' => ['fragments'],
                'groups' => [
                  [
                    'label' => 'Text Heavy',
                    'types' => ['copy', 'blockquote','testimonials', 'doubleColumnWithBackground'],
                  ],
                  [
                    'label' => 'Imagery',
                    'types' => ['imageCopy','fullWidthImage', 'squareCards', 'credentials'],
                  ],
                  [
                    'label' => 'Other',
                    'types' => ['fragment', 'callToAction', 'featuredProjects', 'press', 'contactCards', 'team', 'addForm'],
                  ],
                ],
            ],
        ],
    ],
];

now the fragments channel is using groups, but I have to create them twice and the fragment is not hidden. If I remove the fragment from the group - it is visible but not in a group.

What I expect to happen is I create groups in the wildcard section and they apply everywhere. I then hide the fragments from the fragment channel and it's hidden. But this is not happening.

mmikkel commented 2 years ago

MatrixMate config contexts are not inherited, i.e. the global config (*) will not be merged into your 'section:fragments' config – which is why you have to "create them twice". This is by design and working as intended, see #29 and the section I just added to the readme (as this has come up a few times) for an explanation and a workaround.

So, your last example should actually work – but it looks like you've got 'fragments' instead of 'fragment' for the hiddenTypes setting inside the 'section:fragments' config context, that's probably the reason why the block type isn't being hidden (assuming it's actually called 'fragment', as per your 'groups' config)?

CreateSean commented 2 years ago

Thank you - I did have a typo and used the updated readme to get it working with this:

<?php

$globalConfig = [
  'groups' => [
    [
      'label' => 'Text Heavy',
      'types' => ['copy', 'blockquote','testimonials', 'doubleColumnWithBackground'],
    ],
    [
      'label' => 'Imagery',
      'types' => ['imageCopy','fullWidthImage', 'squareCards', 'credentials'],
    ],
    [
      'label' => 'Other',
      'types' => ['fragment', 'callToAction', 'featuredProjects', 'press', 'contactCards', 'team', 'addForm'],
    ],
  ],
];

return [
    'fields' => [
        'contentBuilder' => [
            '*' => $globalConfig,
            'section:fragments' => array_merge_recursive($globalConfig, [
              'hiddenTypes' => ['fragment'],
            ]),
        ],
    ],
];
mmikkel commented 2 years ago

@CreateSean Great, thanks for the follow-up!