public function getEagerLoadingMap($sourceElements, $handle) { $superTableFieldId = $sourceElements[0]->fieldId; $blockTypes = craft()->superTable->getBlockTypesByFieldId($superTableFieldId); if (!isset($blockTypes[0])) { return false; } $blockType = $blockTypes[0]; // Set the field context $contentService = craft()->content; $originalFieldContext = $contentService->fieldContext; $contentService->fieldContext = 'superTableBlockType:' . $blockType->id; $map = parent::getEagerLoadingMap($sourceElements, $handle); $contentService->fieldContext = $originalFieldContext; return $map; }
/** * @inheritDoc IElementType::getEagerLoadingMap() * * @param BaseElementModel[] $sourceElements * @param string $handle * * @return array|false */ public function getEagerLoadingMap($sourceElements, $handle) { if ($handle == 'author') { // Get the source element IDs $sourceElementIds = array(); foreach ($sourceElements as $sourceElement) { $sourceElementIds[] = $sourceElement->id; } $map = craft()->db->createCommand()->select('id as source, authorId as target')->from('entries')->where(array('in', 'id', $sourceElementIds))->queryAll(); return array('elementType' => 'User', 'map' => $map); } return parent::getEagerLoadingMap($sourceElements, $handle); }
/** * @inheritDoc IElementType::getEagerLoadingMap() * * @param BaseElementModel[] $sourceElements * @param string $handle * * @return array|false */ public function getEagerLoadingMap($sourceElements, $handle) { // $handle *must* be set as "blockTypeHandle:fieldHandle" so we know _which_ myRelationalField to resolve to $handleParts = explode(':', $handle); if (count($handleParts) != 2) { return false; } list($blockTypeHandle, $fieldHandle) = $handleParts; // Get the block type $matrixFieldId = $sourceElements[0]->fieldId; $blockTypes = craft()->matrix->getBlockTypesByFieldId($matrixFieldId, 'handle'); if (!isset($blockTypes[$blockTypeHandle])) { // Not a valid block type handle (assuming all $sourceElements are blocks from the same Matrix field) return false; } $blockType = $blockTypes[$blockTypeHandle]; // Set the field context $contentService = craft()->content; $originalFieldContext = $contentService->fieldContext; $contentService->fieldContext = 'matrixBlockType:' . $blockType->id; $map = parent::getEagerLoadingMap($sourceElements, $fieldHandle); $contentService->fieldContext = $originalFieldContext; return $map; }