$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);
$block_manager = \Drupal::service('plugin.manager.block');
#!/usr/bin/env bash | |
# Credit to keraion for huge readability improvements and parallelization. | |
set -e | |
# Creates webp / avif images for images that don't already exist and places them in the public folder | |
# This script can take a while to run | |
# Install deps | |
# sudo apt-get install -f webp ffmpeg |
<?php | |
namespace Drupal\mymodule\Plugin\Block; | |
use Drupal\Core\Block\BlockBase; | |
use Drupal\Core\Form\FormStateInterface; | |
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | |
use Drupal\file\Entity\File; | |
use Drupal\file\FileUsage\FileUsageInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; |
<?php | |
// How to create horizontal tabs programmatically in Drupal 8, requires Field Group module | |
$form = array(); | |
$form['my_field'] = array( | |
'#type' => 'horizontal_tabs', | |
'#tree' => TRUE, | |
'#prefix' => '<div id="unique-wrapper">', | |
'#suffix' => '</div>', | |
); | |
$items = array( |
Please note I created that sheet as a personal side note/draft and not everything is fully tested. There could be errors or better things to do. So if you spot something wrong or something that can be improved, feel free to comment below and I will do the changes.
Image path: {{ file_url(content.field_name['#items'].entity.uri.value) }}
use Drupal\Core\Url; | |
use Symfony\Component\HttpFoundation\Request; | |
function my_function() { | |
$previousUrl = \Drupal::request()->server->get('HTTP_REFERER'); | |
$fake_request = Request::create($previousUrl); | |
$url_object = \Drupal::service('path.validator')->getUrlIfValid($fake_request->getRequestUri()); | |
if ($url_object) { | |
$route_name = $url_object->getRouteName(); | |
// Do something with $route_name; |
<?php | |
/** | |
* @file | |
* Contains Drupal\mymodule\Plugin\Block\ImageRenderExampleBlockByURI. | |
*/ | |
namespace Drupal\mymodule\Plugin\Block; | |
use Drupal\Core\Block\BlockBase; |