Jump to content

My RepeaterMatrix scripts


Clarity
 Share

Recommended Posts

Hello everyone!

Recently I wrote these scripts for TracyDebugger console in order to make work with RepeaterMatrix easier and faster. I want to present them to the community.

Show relationship between all types, names and labels.

$repeaterMatrixModule = $modules->get('FieldtypeRepeaterMatrix');
$fieldName = 'content_blocks';
$repeaterMatrixField = $fields->get($fieldName);
$typesArray = [];
foreach($repeaterMatrixModule->getMatrixTypes() as $matrixName => $matrixType) {
    $typesArray[$matrixName] = $matrixType . ' ' . $repeaterMatrixModule->getMatrixTypeLabel($matrixType, $repeaterMatrixField);
}
db($typesArray);

RepeaterMatrix9.thumb.jpg.a41862f523b7844be507814dcf169f2c.jpg

Show all pages which have specific type in field (repeater_matrix) with this name:

$repeaterMatrixModule = $modules->get('FieldtypeRepeaterMatrix');
$typeName = 'block_text';
$fieldName = 'content_blocks';
$repeaterMatrixField = $fields->get($fieldName);
$typeId = $repeaterMatrixModule->getMatrixTypeByName($typeName, $repeaterMatrixField);
$typeLabel = $repeaterMatrixModule->getMatrixTypeLabel($typeId, $repeaterMatrixField);
$pagesWithType = $pages->find("{$fieldName}.type={$typeName}");
db($pagesWithType);
db($typeLabel, 'Name of type');

RepeaterMatrix8.jpg.fc9f5d9d2569b4ff1f56bab9c3ce72db.jpg

This list can be continued as soon as I'll invent more scripts.

Edited by Clarity
Updated scripts.
  • Like 9
Link to comment
Share on other sites

Thanks for sharing. Your 2nd example can also be written like this

$fieldName = 'content_product';
$typeName = 'product_downloads';
$pagesWithType = $pages->find("{$fieldName}.type={$typeName}");
db($pagesWithType);

1260836016_2023-02-01-084317.thumb.png.06dd237ec12b700e57eaafbfdfbf5065.png

No need for looping through all pages. find() accepts the subselector .type. Only drawback with my solution: you don't get the label for the type. 

Actually when trying your example, $typeId returned false and $typeName returned null

$repeaterMatrix = $modules->get('FieldtypeRepeaterMatrix');
$typeId = $repeaterMatrix->getMatrixTypeByName('product_downloads');
db($typeId, '$typeId'); // returns false
$typeName = $repeaterMatrix->getMatrixTypeLabel($typeId);
db($typeName, '$typeName'); // returns null

Which version of Repeater Matrix are you using?

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

4 hours ago, gebeer said:

Actually when trying your example, $typeId returned false and $typeName returned null

$repeaterMatrix = $modules->get('FieldtypeRepeaterMatrix');
$typeId = $repeaterMatrix->getMatrixTypeByName('product_downloads');
db($typeId, '$typeId'); // returns false
$typeName = $repeaterMatrix->getMatrixTypeLabel($typeId);
db($typeName, '$typeName'); // returns null

Which version of Repeater Matrix are you using?

I found the reason. It works if you only have 1 repeater matrix field. If you have multiple, you need to pass the field object as 2nd parameter:

$field = $fields->get('content_product');
$repeaterMatrix = $modules->get('FieldtypeRepeaterMatrix');
$typeId = $repeaterMatrix->getMatrixTypeByName('teaser_gallery', $field);

Same goes for $repeaterMatrix->getMatrixTypeLabel(string 'typename', Field $field)

  • Thanks 1
Link to comment
Share on other sites

@gebeer, thank you for improving my scripts. I've updated them.

5 hours ago, gebeer said:

Thanks for sharing. Your 2nd example can also be written like this

$fieldName = 'content_product';
$typeName = 'product_downloads';
$pagesWithType = $pages->find("{$fieldName}.type={$typeName}");
db($pagesWithType);

Also my previous version of this script finds pages in repeaters which is not an intended behavior.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...