@param MatrixBlockType[] $oldBlockTypes
@param array $newBlockTypes

@return array

@throws \yii\base\InvalidConfigException
191477
private function mergeBlockTypes(array $oldBlockTypes, array $newBlockTypes): array
    {
        $oldIDs = array_map(function($a) { return $a['id']; }, $oldBlockTypes);
        $oldHandles = array_map(function($a) { return $a['handle']; }, $oldBlockTypes);
        $updatedBlockTypes = [];
        $newCount = 1;
        foreach ($newBlockTypes as $newIndex => $blockType) {
            if (isset($blockType['id'])) {
                $oldIndex = array_search($blockType['id'], $oldIDs, false);
            } else {
                $oldIndex = array_search($blockType['handle'], $oldHandles, false);
            }
            if ($oldIndex !== false) {
                $oldFieldLayout = $oldBlockTypes[$oldIndex]->getFieldLayout();
                $newFields = $blockType['fields'];
            } else {
                $oldFieldLayout = new FieldLayout();
                $newFields = [];
            }
            $blockType['fields'] = $this->mergeFieldLayout($oldFieldLayout, $newFields);
            if ($oldIndex !== false) {
                $updatedBlockTypes[$oldBlockTypes[$oldIndex]['id']] = $blockType;
            } else {
                $updatedBlockTypes['new' . $newCount] = $blockType;
                $newCount++;
            }
        }
        return $updatedBlockTypes;
    }
456769
protected function handleBlockRendering($blocks)
    {
        foreach ($blocks as &$block) {
            $type        = resolve($block->type->handler);
            $block->view = $type->handle($block, $this->languageService->getCurrent());
        }
    }
367025
public function setAllBlockRows($removeDefs=true) {
		$defs = $this->get_block_row_defs($removeDefs);
		
		foreach($defs as $rowName) {
			$this->setBlockRow($rowName);
		}

		return($this->_blockRows);
	}
484626
protected function readConfigs(array $blockPaths)
    {
        $pluginConfigs = [];

        foreach ($blockPaths as $blockPath) {
            $pluginDir = $blockPath;
            $configFileName = $pluginDir . '/block.json';
            $this->assertPathValid($configFileName);
            $configFileContents = file_get_contents($configFileName);
            $config = json_decode($configFileContents, true, 512, JSON_BIGINT_AS_STRING);
            if (json_last_error() !== JSON_ERROR_NONE) {
                throw new \Exception('Received invalid JSON for: ' . $configFileName);
            }
            $config['directory'] = realpath($pluginDir);
            $pluginConfigs[$config['name']] = $config;
        }

        return $pluginConfigs;
    }
70008
public function migrateCkeditorBlocks()
    {
        $legacyBlocks = $this->getLegacyCkeditorBlocks();

        foreach ($legacyBlocks as $legacyBlock) {
            $legacyBlock->setType('cms.block.ckeditor');

            $settings = $legacyBlock->getSettings();

            if (isset($settings['contenu'])) {
                $settings['content'] = $settings['contenu'];
                unset($settings['contenu']);
            }

            $legacyBlock->setSettings($settings);

            $this->blockManager->save($legacyBlock);
        }
    }
855179
public function create($rowOrName, $type = null, array $data = [])
    {
        // Check if row or name is defined
        if (!(
            $rowOrName instanceof Model\RowInterface ||
            (is_string($rowOrName) && 0 < strlen($rowOrName))
        )
        ) {
            throw new InvalidOperationException("Excepted instance of RowInterface or string.");
        }

        // Default type if null
        if (null === $type) {
            $type = $this->defaultType;
        }

        // New instance
        $block = $this->editor->getRepository()->createBlock();
        $block->setType($type);

        // Layout creation
//        $this->editor->getLayoutAdapter()->createBlock($block, $data);

        // Plugin creation
        $this->editor->getBlockPlugin($type)->create($block, $data);

        // Add to row if available
        if ($rowOrName instanceof Model\RowInterface) {
            $count = $rowOrName->getBlocks()->count();
            $block
                ->setPosition($count);

            $rowOrName->addBlock($block);
        } else {
            $block->setName($rowOrName);
        }

        return $block;
    }
1353582
protected function validateTypes(array $types)
    {
        foreach ($types as $key => $val) {
            if (!is_string($key)) {
                throw new Exception\InvalidArgumentException(
                    'Keys of $types array must be strings.'
                );
            }
            if (!$val instanceof BlockTypeInterface) {
                throw new Exception\InvalidArgumentException(
                    'Each item of $types array must be BlockTypeInterface.'
                );
            }
        }
    }
408092
protected function makeOutputBlock($type, $selectors = null)
    {
        $out = new OutputBlock;
        $out->type         = $type;
        $out->lines        = [];
        $out->children     = [];
        $out->parent       = $this->scope;
        $out->selectors    = $selectors;
        $out->depth        = $this->env->depth;
        $out->sourceName   = $this->env->block->sourceName;
        $out->sourceLine   = $this->env->block->sourceLine;
        $out->sourceColumn = $this->env->block->sourceColumn;

        return $out;
    }
1215166
private function blocksToArray(array $slotBlocks)
    {
        foreach ($slotBlocks as $block) {
            $aBlock = $block->toArray();
            unset($aBlock["Id"]);

            $this->arrayBlocks[] = $aBlock;
        }
    }
1293216
public function getBlockTypeComposerTemplates()
    {
        $btHandle = $this->getBlockTypeHandle();
        $files = array();
        $fh = Loader::helper('file');
        $dir = DIR_FILES_BLOCK_TYPES . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
        if (is_dir($dir)) {
            $files = array_merge($files, $fh->getDirectoryContents($dir));
        }
        foreach (PackageList::get()->getPackages() as $pkg) {
            $dir =
                (is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES : DIR_PACKAGES_CORE)
                . '/' . $pkg->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $btHandle . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
            if (is_dir($dir)) {
                $files = array_merge($files, $fh->getDirectoryContents($dir));
            }
        }
        $dir = DIR_FILES_BLOCK_TYPES_CORE . "/{$btHandle}/" . DIRNAME_BLOCK_TEMPLATES_COMPOSER;
        if (file_exists($dir)) {
            $files = array_merge($files, $fh->getDirectoryContents($dir));
        }
        $templates = array();
        foreach (array_unique($files) as $file) {
            $templates[] = new TemplateFile($this, $file);
        }

        return TemplateFile::sortTemplateFileList($templates);
    }
1261421
private static function getBlocksWithEnd(array $serializedBlocks): array
    {
        $blocksWithEnd = BlockSerializer::unserializeBlocksWithEnd($serializedBlocks);

        // check result contain only block indexes and the blocks are procedures
        assert(
            is_array($blocks = static::getBlocks($serializedBlocks)) &&
            static::debugCheckBlocksExist($blocksWithEnd, $blocks, BlockSerializer::TYPE__PROCEDURE)
        );

        return $blocksWithEnd;
    }
388783
public function loadBlockColumns()
    {
        $blockColumns = [];
        $parentModelName = static::$parentModel;

        if ($parentModelName) {
            /** @var BaseModel $parentModel */
            $parentModelNameSpace = "\\PhalconRest\\Models\\" . $parentModelName;
            $parentModel = new $parentModelNameSpace();
            $blockColumns = $parentModel->getBlockColumns();

            // the parent model may return null, let's catch and change to an empty array
            // thus indicated that block columns have been "loaded" even if they are blank
            if ($blockColumns == null) {
                $blockColumns = [];
            }
        }
        $this->setBlockColumns($blockColumns, true);
    }
1321792
public function setTypeAttribute($type)
    {
        if (!$type instanceof BlockType) {
            $type = BlockType::getByName($type);
        }
        if (!$type) {
            throw new InvalidArgumentException('Unknown block type');
        }
        $this->type()->associate($type);
    }
1318885
protected function ensureInitialized($blockType)
    {
        if ($blockType instanceof BlockTypeInterface) {
            $name = $blockType->getName();
            $type = $blockType;
        } else {
            $name = $blockType;
            $type = null;
        }

        if (!isset($this->types[$name])) {
            if (!$type) {
                $type = $this->registry->getType($name);
            }

            $types      = [$type];
            $typeName   = $type->getName();
            $names      = [$typeName];
            $nameMap    = [$typeName => true];
            $parentName = $type->getParent();
            while ($parentName) {
                if (isset($this->types[$parentName])) {
                    // use data from already loaded parent type
                    $types   = array_merge($this->types[$parentName], array_reverse($types));
                    $names   = array_merge($this->names[$parentName], array_reverse($names));
                    $nameMap = array_merge($nameMap, $this->nameMap[$parentName]);
                    break;
                } else {
                    $type     = $this->registry->getType($parentName);
                    $typeName = $type->getName();

                    $types[]            = $type;
                    $names[]            = $typeName;
                    $nameMap[$typeName] = true;

                    $parentName = $type->getParent();
                }
            }

            if (null === $parentName) {
                $types = array_reverse($types);
                $names = array_reverse($names);
            }

            $this->types[$name]   = $types;
            $this->names[$name]   = $names;
            $this->nameMap[$name] = $nameMap;

            // initialise all parent types if them are not initialized yet
            $typeNames = array_keys($nameMap);
            $offset    = 0;
            while (false !== ($typeName = next($typeNames))) {
                if (isset($this->nameMap[$typeName])) {
                    break;
                }

                $offset++;
                $this->types[$typeName]   = array_slice($types, 0, -$offset);
                $this->names[$typeName]   = array_slice($names, 0, -$offset);
                $this->nameMap[$typeName] = array_slice($nameMap, $offset);
            }
        }

        return $name;
    }
1027102
public function getBlockTypes(): array
    {
        if ($this->_blockTypes !== null) {
            return $this->_blockTypes;
        }

        if ($this->getIsNew()) {
            return [];
        }

        return $this->_blockTypes = SuperTable::$plugin->getService()->getBlockTypesByFieldId($this->id);
    }
406488
protected function getBlocks()
    {
        $blocks = [];

        foreach ($this->blocks as $key => $value) {
            $blocks[$key] = 'Caouecs\\Sirtrevorjs\\Converter\\'.$value.'Converter';
        }

        if (!empty($this->customBlocks)) {
            $blocks = array_merge($blocks, $this->customBlocks);
        }

        if (isset($this->config['customBlocks']) && !empty($this->config['customBlocks'])) {
            $blocks = array_merge($blocks, $this->config['customBlocks']);
        }

        return $blocks;
    }
52028
public function doDiff( array $oldValues, array $newValues ): array {
		$newSet = $this->arrayDiffAssoc( $newValues, $oldValues );
		$oldSet = $this->arrayDiffAssoc( $oldValues, $newValues );

		$diffSet = [];

		foreach ( $this->getAllKeys( $oldSet, $newSet ) as $key ) {
			$diffOp = $this->getDiffOpForElement( $key, $oldSet, $newSet );

			if ( $diffOp !== null ) {
				$diffSet[$key] = $diffOp;
			}
		}

		return $diffSet;
	}