Load page block data for all live versions of a block across all pages
@param int $blockId
@param bool $reload
@return PageBlock[]
160751
public static function livePageBlocksForBlock($blockId, $reload = false)
    {
        if ($reload) {
            static::_preloadClear('liveBlocks');
        }
        if (!static::_preloadIsset('liveBlocks', $blockId)) {
            $pageBlocks = Block::getDataForVersion(new static, -1, ['block_id' => $blockId, 'language_id' => Language::current()]);
            static::_preload($pageBlocks, 'liveBlocks', [['block_id']], null, true);
        }
        return static::_preloadGet('liveBlocks', $blockId) ?: [];
    }
714147
public function execute(BlockInterface $block, Response $response = null, array $parameters = [])
    {
        $this->loadCollection($block);

        return parent::execute($block, $response, $parameters);
    }
331177
public function loadBlock($id)
    {
        $block = $this->entityTypeManager->getStorage('block')->load($id);


        return $block ? $this->entityTypeManager->getViewBuilder('block')->view($block) : '';
    }
568901
public function getBlock($block_id, $template = true, $cfg = array()) {
        Globals::getController()->addInlineJavascript('
			$(document).ready(function(){
				$.ajax({
					url: "module.php",
					data : {
						mod: "'.$this->getName().'",
						mod_action: "Task@trigger",
					},
				});
			});
		');
        return '';
    }
786665
public function detachAllPermissions($reload = true)
    {
        event(new DetachingAllPermissions($this));
        $detached = $this->permissions()->update(['group_id' => 0]);
        event(new DetachedAllPermissions($this, $detached));

        $this->loadPermissions($reload);

        return $detached;
    }
893399
public function detachAllRoles($reload = true)
    {
        event(new DetachingRolesFromUser($this));
        $results = $this->roles()->detach();
        event(new DetachedRolesFromUser($this, $results));

        $this->loadRoles($reload);

        return $results;
    }
1262366
public function blockerIds(bool $collection = false)
    {
        $ids = $this->blockerUsers()->pluck($this->getTable().'.id');

        if ($collection) {
            return $ids;
        }

        return $ids->toArray();
    }
832297
public function loadMessages($blockName) {
        $messages = $this->getMessages();
        if (is_array(@$messages[$blockName])) {
            return $messages[$blockName];
        } else {
            return array();
        }
    }
753044
public function execute(Request $request, $pageId, $blockId)
    {
        $cmsManager = $this->cmsManagerSelector->retrieve();

        $page = $cmsManager->getPageById($pageId);
        $block = $cmsManager->getBlock($blockId);

        if (!$block instanceof BlockInterface) {
            throw new BlockNotFoundException(sprintf('Unable to find block identifier "%s" in page "%s".', $blockId, $pageId));
        }

        $blockContext = $this->contextManager->get($block);

        return $this->blockRenderer->render($blockContext);
    }
30052
public function loadBlock($id)
    {
        if (isset($this->blocksById[$id])) {
            return $this->blocksById[$id];
        }

        $contentId = $this->getStorageGateway()->getContentIdByBlockId($id);
        $content = $this->contentService->loadContent($contentId);

        foreach ($content->getFields() as $field) {
            if (!$field->value instanceof Value) {
                continue;
            }

            foreach ($field->value->page->zones as $zone) {
                foreach ($zone->blocks as $block) {
                    if ($block->id === $id) {
                        return $this->blocksById[$id] = $block;
                    }
                }
            }
        }

        throw new NotFoundException('Block', $id);
    }
131837
protected function loadCarouselItemsForBlock(BlockInterface $block)
    {
        $settings = $block->getSettings();

        return $this->container->get('doctrine')
            ->getRepository('Presta\CMSMediaBundle\Doctrine\Orm\Carousel')
            ->findLimited();
    }
1316896
public function detachAllRoles($reload = true)
    {
        event(new DetachingAllRolesFromPermission($this));
        $results = $this->roles()->detach();
        event(new DetachedAllRolesFromPermission($this, $results));

        $this->loadRoles($reload);

        return $results;
    }
1055268
private function _commitBlocks($url, $blockIds)
    {
        $baseUrl = new Url($url);
        $baseUrl->setQueryVariable(Resources::QP_COMP, 'blocklist');

        $xml = new \XMLWriter();

        $xml->openMemory();
        $xml->setIndent(true);

        $xml->startDocument('1.0', 'UTF-8');

        $xml->startElement('BlockList');

        foreach ($blockIds as $blockId) {
            $xml->writeElement('Latest', $blockId);
        }

        $xml->endElement();

        $xml->endDocument();

        $xmlContent = $xml->outputMemory();

        $method = Resources::HTTP_PUT;
        $filters = [];
        $statusCode = Resources::STATUS_CREATED;
        $headers = [
            Resources::CONTENT_TYPE => Resources::BINARY_FILE_TYPE,
            Resources::X_MS_VERSION => Resources::STORAGE_API_LATEST_VERSION,
        ];

        $httpClient = new HttpClient();
        $httpClient->setMethod($method);
        $httpClient->setHeaders($headers);
        $httpClient->setExpectedStatusCode($statusCode);
        $httpClient->setBody($xmlContent);
        $httpClient->send($filters, $baseUrl);
    }
526961
private function loadBlocks(PageInterface $page)
    {
        $blocks = $this->blockInteractor->loadPageBlocks($page);

        // save a local cache
        foreach ($blocks as $block) {
            $this->blocks[$block->getId()] = $block;
        }
    }
901889
public static function get_blockids_from_courseid($courseid) {
        global $DB;

        // Get the context of the course
        $contextid = context_course::instance($courseid)->id;

        // Get all the block instances which parentcontextid is the course contextid
        $blockids = array();
        $instances = $DB->get_records('block_instances', array('parentcontextid' => $contextid), '', 'id');
        foreach ($instances as $instance) {
            $blockids[] = $instance->id;
        }
        return $blockids;
    }
682622
private function _createBlocksFromSerializedData($value, ElementInterface $element = null): array
    {
        if (!is_array($value)) {
            return [];
        }

        /** @var Element $element */
        // Get the possible block types for this field
        /** @var SuperTableBlockType[] $blockTypes */
        $blockTypes = ArrayHelper::index(SuperTable::$plugin->getService()->getBlockTypesByFieldId($this->id), 'id');

        $oldBlocksById = [];

        // Get the old blocks that are still around
        if ($element && $element->id) {
            $ownerId = $element->id;

            $ids = [];

            foreach (array_keys($value) as $blockId) {
                if (is_numeric($blockId) && $blockId != 0) {
                    $ids[] = $blockId;

                    // If that block was duplicated earlier in this request, check for that as well.
                    if (isset(Elements::$duplicatedElementIds[$blockId])) {
                        $ids[] = Elements::$duplicatedElementIds[$blockId];
                    }
                }
            }

            if (!empty($ids)) {
                $oldBlocksQuery = SuperTableBlockElement::find();
                $oldBlocksQuery->fieldId($this->id);
                $oldBlocksQuery->ownerId($ownerId);
                $oldBlocksQuery->id($ids);
                $oldBlocksQuery->anyStatus();
                $oldBlocksQuery->siteId($element->siteId);
                $oldBlocksQuery->indexBy('id');
                $oldBlocksById = $oldBlocksQuery->all();
            }
        } else {
            $ownerId = null;
        }

        $isLivePreview = Craft::$app->getRequest()->getIsLivePreview();
        $blocks = [];
        $sortOrder = 0;
        $prevBlock = null;

        foreach ($value as $blockId => $blockData) {
            if (!isset($blockData['type']) || !isset($blockTypes[$blockData['type']])) {
                continue;
            }

            $blockType = $blockTypes[$blockData['type']];

            // If this is a preexisting block but we don't have a record of it,
            // check to see if it was recently duplicated.
            if (
                strpos($blockId, 'new') !== 0 &&
                !isset($oldBlocksById[$blockId]) &&
                isset(Elements::$duplicatedElementIds[$blockId])
            ) {
                $blockId = Elements::$duplicatedElementIds[$blockId];
            }

            // Is this new? (Or has it been deleted?)
            if (strpos($blockId, 'new') === 0 || !isset($oldBlocksById[$blockId])) {
                $block = new SuperTableBlockElement();
                $block->fieldId = $this->id;
                $block->typeId = $blockType->id;
                $block->ownerId = $ownerId;
                $block->siteId = $element->siteId;
            } else {
                $block = $oldBlocksById[$blockId];
            }

            $block->setOwner($element);

            // Set the content post location on the block if we can
            $fieldNamespace = $element->getFieldParamNamespace();

            if ($fieldNamespace !== null) {
                $blockFieldNamespace = ($fieldNamespace ? $fieldNamespace . '.' : '') . $this->handle . '.' . $blockId . '.fields';
                $block->setFieldParamNamespace($blockFieldNamespace);
            }

            if (isset($blockData['fields'])) {
                foreach ($blockData['fields'] as $fieldHandle => $fieldValue) {
                    try {
                        $block->setFieldValue($fieldHandle, $fieldValue);
                    } catch (UnknownPropertyException $e) {
                        // the field was probably deleted
                    }
                }
            }
            
            $sortOrder++;
            $block->sortOrder = $sortOrder;

            // Set the prev/next blocks
            if ($prevBlock) {
                /** @var ElementInterface $prevBlock */
                $prevBlock->setNext($block);
                /** @var ElementInterface $block */
                $block->setPrev($prevBlock);
            }
            $prevBlock = $block;

            $blocks[] = $block;
        }

        return $blocks;
    }
576791
public function loadBlockCollectionIds(array $blockIds, ?int $status = null): array
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT bc.collection_id')
            ->from('ngbm_block_collection', 'bc')
            ->where(
                $query->expr()->in('bc.block_id', [':block_id'])
            )
            ->setParameter('block_id', $blockIds, Connection::PARAM_INT_ARRAY);

        if ($status !== null) {
            $this->applyStatusCondition($query, $status, 'bc.block_status', 'block_status');
        }

        $result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return array_column($result, 'collection_id');
    }