Validate block for correctness

@param string $blockType
@param array  $blockData

@throws EditorJSException

@return bool
489120
public function validateBlock($blockType, $blockData)
    {
        /**
         * Default action for blocks that are not mentioned in a configuration
         */
        if (!array_key_exists($blockType, $this->rules->tools)) {
            throw new EditorJSException("Tool `$blockType` not found in the configuration");
        }

        $rule = $this->rules->tools[$blockType];

        return $this->validate($rule, $blockData);
    }
778895
public function deleteBlockType(SuperTableBlockTypeModel $blockType): bool
    {
        Craft::$app->getProjectConfig()->remove(self::CONFIG_BLOCKTYPE_KEY . '.' . $blockType->uid);

        return true;
    }
84522
public function validate($formData)
	{
		$formData = $this->normalizeFormData($formData);

		$this->validation = $this->validator->make(
			$formData,
			$this->getValidationRules(),
			$this->getValidationMessages()
		);

		if ($this->validation->fails())
		{
			throw new FormValidationException('Validation failed', $this->getValidationErrors());
		}

		return true;
	}
1303072
private function validateBlocks()
    {
        foreach ($this->blocks as $block) {
            if (!$this->handler->validateBlock($block['type'], $block['data'])) {
                return false;
            }
        }

        return true;
    }
1222016
function(source, type) {
  if (source.hasOwnProperty('format')) {
    if (source.format !== type) {
      if (source.format === 'section') {
        var blocks = [];
        source.blocks.forEach(function(val, index, array) {
          var block = deleteTextBlockFormat(val, type);
          if (block) {
            blocks.push(block);
          }
        });
        if (blocks.length) {
          return {format: 'section', blocks: blocks};
        } else {
          return null;
        }
      } else {
        return source;
      }
    } else {
      return null;
    }
  }
  throw new Error('invalid format for textblock (did you pass an Object in?)');
}
840857
private function validateViewIds(BlockInterface $block = null, BlockView $view)
    {
        if (!$block->getOption('render_id')) {
            return;
        }

        $id = $view->vars['id'];
        $hash = spl_object_hash($block);
        $newIds = [$hash];

        if (isset($this->viewIds[$id]) && !\in_array($hash, $this->viewIds[$id])) {
            $this->data['duplicate_ids'][] = $id;
            $this->data['duplicate_ids'] = array_unique($this->data['duplicate_ids']);

            $newIds = array_merge($this->viewIds[$id], $newIds);
        }

        $this->viewIds[$id] = $newIds;
    }
933564
public function addElement($blockType, array $element)
	{
        $this->blockType = $blockType;
		$this->label = $element["description"];
        $this->filter = $element["filter"];
		$this->type = 'element';
	}
1374147
public function renderBlock($block, $type = null, array $data = [])
    {
        if (is_string($block)) {
            if (null === $element = $this->editor->getRepository()->findBlockByName($block)) {
                $this->persist($element = $this->editor->getBlockManager()->create($block, $type, $data));
            }
            $block = $element;
        }

        if ($block instanceof EM\BlockInterface) {
            $this->tagManager->addTags($block->getEntityTag());

            $block = $this->editor->getViewBuilder()->buildBlock($block);
        }

        if (!$block instanceof View\BlockView) {
            throw new Exception\InvalidArgumentException(
                'Expected string or instance of ' .
                EM\BlockInterface::class . ' or ' .
                View\BlockView::class
            );
        }

        return $this->getTemplate()->renderBlock('cms_block', [
            'block' => $block,
        ]);
    }
615420
private function isValidContentType(string $contentType): void
    {
        $allowedContentType = $this->getAllowedContentType();
        if (!\in_array($contentType, $allowedContentType, true)) {
            throw new InvalidTypeException('Invalid content type.');
        }
    }
877897
protected function containsTypeArray($docBlockTypes) {
		foreach ($docBlockTypes as $docBlockType) {
			if (strpos($docBlockType, '[]') !== false) {
				return true;
			}
		}

		return false;
	}
902634
public static function isType(BlockView $view, $type)
    {
        return isset($view->vars['block_prefixes'])
            && \is_array($view->vars['block_prefixes'])
            && \in_array($type, $view->vars['block_prefixes']);
    }
699899
function formatJson_(blockType, rootBlock) {
  var JS = {};
  // Type is not used by Blockly, but may be used by a loader.
  JS.type = blockType;
  // Generate inputs.
  var message = [];
  var args = [];
  var contentsBlock = rootBlock.getInputTargetBlock('INPUTS');
  var lastInput = null;
  while (contentsBlock) {
    if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
      var fields = getFieldsJson_(contentsBlock.getInputTargetBlock('FIELDS'));
      for (var i = 0; i < fields.length; i++) {
        if (typeof fields[i] == 'string') {
          message.push(fields[i].replace(/%/g, '%%'));
        } else {
          args.push(fields[i]);
          message.push('%' + args.length);
        }
      }

      var input = {type: contentsBlock.type};
      // Dummy inputs don't have names.  Other inputs do.
      if (contentsBlock.type != 'input_dummy') {
        input.name = contentsBlock.getFieldValue('INPUTNAME');
      }
      var check = JSON.parse(getOptTypesFrom(contentsBlock, 'TYPE') || 'null');
      if (check) {
        input.check = check;
      }
      var align = contentsBlock.getFieldValue('ALIGN');
      if (align != 'LEFT') {
        input.align = align;
      }
      args.push(input);
      message.push('%' + args.length);
      lastInput = contentsBlock;
    }
    contentsBlock = contentsBlock.nextConnection &&
        contentsBlock.nextConnection.targetBlock();
  }
  // Remove last input if dummy and not empty.
  if (lastInput && lastInput.type == 'input_dummy') {
    var fields = lastInput.getInputTargetBlock('FIELDS');
    if (fields && getFieldsJson_(fields).join('').trim() != '') {
      var align = lastInput.getFieldValue('ALIGN');
      if (align != 'LEFT') {
        JS.lastDummyAlign0 = align;
      }
      args.pop();
      message.pop();
    }
  }
  JS.message0 = message.join(' ');
  if (args.length) {
    JS.args0 = args;
  }
  // Generate inline/external switch.
  if (rootBlock.getFieldValue('INLINE') == 'EXT') {
    JS.inputsInline = false;
  } else if (rootBlock.getFieldValue('INLINE') == 'INT') {
    JS.inputsInline = true;
  }
  // Generate output, or next/previous connections.
  switch (rootBlock.getFieldValue('CONNECTIONS')) {
    case 'LEFT':
      JS.output =
          JSON.parse(getOptTypesFrom(rootBlock, 'OUTPUTTYPE') || 'null');
      break;
    case 'BOTH':
      JS.previousStatement =
          JSON.parse(getOptTypesFrom(rootBlock, 'TOPTYPE') || 'null');
      JS.nextStatement =
          JSON.parse(getOptTypesFrom(rootBlock, 'BOTTOMTYPE') || 'null');
      break;
    case 'TOP':
      JS.previousStatement =
          JSON.parse(getOptTypesFrom(rootBlock, 'TOPTYPE') || 'null');
      break;
    case 'BOTTOM':
      JS.nextStatement =
          JSON.parse(getOptTypesFrom(rootBlock, 'BOTTOMTYPE') || 'null');
      break;
  }
  // Generate colour.
  var colourBlock = rootBlock.getInputTargetBlock('COLOUR');
  if (colourBlock && !colourBlock.disabled) {
    var hue = parseInt(colourBlock.getFieldValue('HUE'), 10);
    JS.colour = hue;
  }
  JS.tooltip = '';
  JS.helpUrl = 'http://www.example.com/';
  return JSON.stringify(JS, null, '  ');
}
1120460
function isBlockBoundary( node ) {
		return node &&
			( node.type == CKEDITOR.NODE_ELEMENT && node.name in blockLikeTags ||
			node.type == CKEDITOR.NODE_DOCUMENT_FRAGMENT );
	}
1249060
protected function validateBlockLayout(array $data)
    {
        foreach (array_keys(static::getDevices()) as $device) {
            // If layout set for this device
            if (!isset($data[$device])) {
                continue;
            }

            $size = isset($data[$device][static::SIZE]) ? $data[$device][static::SIZE] : 12;
            $offset = isset($data[$device][static::OFFSET]) ? $data[$device][static::OFFSET] : 0;

            // Validate size
            if (1 > $size || $size > 12) {
                throw new InvalidArgumentException('Invalid layout size');
            }

            // Validate offset
            if (0 > $offset || $offset > 11) {
                throw new InvalidArgumentException('Invalid layout offset');
            }

            // Validate sum
            if (12 < ($size + $offset)) {
                throw new InvalidArgumentException('Invalid block layout size/offset');
            }
        }
    }
869545
@Override
  public void validate(byte[] blockBuffer, int rowOffset, int rowHead, int blobTail)
  {
    int offset = rowOffset + offset();
    
    int blobLen = BitsUtil.readInt16(blockBuffer, offset + 2);
    int blobOffset = BitsUtil.readInt16(blockBuffer, offset);
    
    if (blobLen == 0) {
      return;
    }
    
    if (blobOffset < 0 || blobTail < blobOffset) {
      throw new IllegalStateException(L.l("{0}: corrupted blob offset {1} with blobTail={2}",
                                          this, blobOffset, blobTail));
    }
    
    if ((blobLen & LARGE_BLOB_MASK) != 0) {
      blobLen &= ~LARGE_BLOB_MASK;
      
      if (blobLen != 4) {
        throw new IllegalStateException(L.l("{0}: corrupted blob len {1} for large blob.",
                                            this, blobOffset));
      }
    }
    
    
    if (blobLen < 0 || blobTail < blobLen + blobOffset) {
      throw new IllegalStateException(L.l("{0}: corrupted blob len {1} with blobOffset={2} blobTail={3}",
                                          this, blobLen, blobOffset, blobTail));
    }
  }
978919
public function preSetData(BlockEvent $event)
    {
        $block = $event->getBlock();
        $data = $event->getData();

        if (null === $data) {
            $data = [];
        }

        if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
        }

        // First remove all rows
        foreach ($block as $name => $child) {
            $block->remove($name);
        }

        // Then add all rows again in the correct order
        foreach ($data as $name => $value) {
            $block->add($name, $this->type, array_replace([
                    'property_path' => '['.$name.']',
            ], $this->options));
        }
    }
410415
public function destroy($contentId, $blockTypeId, $blockId)
    {
        try {
            list($content, $blockType, $block) = array_values($this->contentBlocks->destroy($contentId, $blockTypeId, $blockId));
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.delete', ['object' => trans('soda::terminology.block')]));
        }

        return redirect()->route('soda.content.edit', [$contentId, 'tab' => $this->getTab($blockType)])->with('warning', trans('soda::messages.deleted', ['object' => trans('soda::terminology.block')]));
    }