2

I've got a plugin which needs to be able to access all the blocks in a matrix - regardless of if the blocks are enabled or disabled.

The entry objects returned by the likes of craft()->entries->getEntryById only seem to include blocks in the matrix fields which are enabled.

Is there a way to access this information through a service - or do I need to work out how this is handled in the control panel (which does show disabled matrix blocks)?

2

Something like this should do it:

$criteria = craft()->elements->getCriteria(ElementType::MatrixBlock);
$criteria->status = null;
$find = $criteria->find();

Setting status to null will return all elements regardless of their status.

| improve this answer | |
  • The difficultly I'm having with the manual approach is finding the right criteria to restrict the results to the matrix block content for a specific entry id. I can query the db directly - but following the chain of relationships is proving difficult. – Tom Aug 3 '15 at 16:42
1

If you already have an entry object, and know the handle for the Matrix field, you can use:

$criteria = craft()->elements->getCriteria(ElementType::MatrixBlock);
$criteria->fieldId = craft()->fields->getFieldByHandle('matrixFieldHandle')->id;
$criteria->ownerId = $entry->id;
$criteria->status = null;
$blocks = $criteria->find();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.