Skip to content

Instantly share code, notes, and snippets.

@rovo79
rovo79 / Blocks.md
Created March 22, 2023 01:06 — forked from davidjguru/Blocks.md
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@rovo79
rovo79 / Base64FileManagerService.php
Created September 20, 2022 17:54 — forked from philipnorton42/Base64FileManagerService.php
A Drupal service class that can extract base64 encoded files from HTML content.
<?php
namespace Drupal\mymodule;
use Drupal\Core\File\Exception\FileNotExistsException;
use Drupal\Core\File\FileSystemInterface;
use Drupal\file\FileRepositoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;