Skip to content

Instantly share code, notes, and snippets.

View kedramon's full-sized avatar
🇺🇦
stand with Ukraine

kedramon kedramon

🇺🇦
stand with Ukraine
View GitHub Profile
@bdlangton
bdlangton / Blocks.md
Last active October 12, 2023 08:40
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');
@steffenr
steffenr / file_media_entity.php
Last active February 27, 2023 18:33
[Drupal 8] Create file/ media_entity programmatically
<?php
$filesystem = \Drupal::service('file_system');
// Create file entity.
$image = File::create();
$image->setFileUri($destination);
$image->setOwnerId(\Drupal::currentUser()->id());
$image->setMimeType('image/' . pathinfo($destination, PATHINFO_EXTENSION));
$image->setFileName($filesystem->basename($destination));
$image->setPermanent();
$image->save();
@kedramon
kedramon / article.md
Last active July 26, 2016 09:33
Entity reference - customizability at its best

This article is a copy of http://kybest.hu/en/blog/entity-reference-customizability-at-its-best from google cache. I found it usefull

#Entity reference - customizability at its best

Submitted by CZÖVEK András on 2013-11-26, Tuesday, 17:29 The Entity reference module is one of the most used Drupal modules. At the moment of writing it is 51st on the usage list of Drupal projects. Those who have already made a Drupal site probably have knows it. At the same time, not many know what a powerful tool it can be even in special cases.

The quality of a Drupal module is quite well characterized by its customizability. If a module produces markup for instance we expect to be able to alter that markup through the theme layer of Drupal. The Entity reference is an excellently written module in this aspect (too). But what should be customized in the Entity reference module?

In one of the sites recently produced by us one part of the content comes from an external source. These contents are digitalized books stored on t

@diegonobre
diegonobre / symfony3-rest-api.md
Last active February 21, 2025 21:56 — forked from tjamps/README.md
Basic RESTful API with Symfony 3 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 3 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authenticationu
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 3 framework. The following SF2 bundles are used :

#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@juampynr
juampynr / mymodule.info
Last active June 9, 2023 21:53
Drupal 7 Views 3 custom field handler
dependencies[] = ctools
; Views Handlers
files[] = views/mymodule_handler_handlername.inc