Skip to content

Instantly share code, notes, and snippets.


Jesus Manuel Olivas jmolivas

View GitHub Profile
jmolivas / DefaultController.php
Last active Aug 20, 2022
Drupal 8 example: How to render a Twig template and load a CSS file from a Controller
View DefaultController.php
namespace Drupal\acme\Controller;
use Drupal\Core\Controller\ControllerBase;
class DefaultController extends ControllerBase
jmolivas / script.js
Last active Feb 6, 2021
Trigger Netlify build from a Google Spreadsheet
View script.js
# From your Google Spreadsheet, select the menu item Tools > Script editor.
# Copy and paste this code.
# Replace uuid with the build_hooks uuid from your Netlify project.
function onOpen() {
.addItem('Build', 'build')
jmolivas /
Last active Jul 28, 2020
Inject a service from the service container

Inject a Service in Drupal 8

Is a good practice to inject a service whenever is possible.

You can verify the service name by:

Looking at the Drupal Static Service Container wrapper class.

Reading the code on the Drupal Class you can find the httpClient method:

jmolivas /
Created Jun 12, 2020 — forked from KalleVuorjoki/
Script to crawl Drupal JSON:API endpoint to local filesystem.
# Script to crawl Drupal JSON:API endpoint to local filesystem.
# Assumes endpoint to be /jsonapi and uses basic auth.
# Requirements:
# ag -
# jq -
View gatsby-node.js
exports.createResolvers = ({ actions, getCache, createNodeId, createResolvers }) => {
const { createNode } = actions
Drupal_MediaImage: {
gatsbyImageFile: {
type: `File`,
resolve(source) {
return createRemoteFileNode({
jmolivas /
Last active May 1, 2020
Improve your shell with fish and oh my fish.
brew install fish
View MyRestResource.php
* @file
* Contains \Drupal\my_module\Plugin\rest\resource\MyRestResource.
namespace Drupal\my_module\Plugin\rest\resource;
use Drupal\Core\Session\AccountProxyInterface;
jmolivas / gatsby-node.js
Last active Feb 7, 2020
Drupal + GraphQL + Gatsby code snippets
View gatsby-node.js
const path = require("path");
const { createRemoteFileNode } = require(`gatsby-source-filesystem`);
// GraphQL Schema customization to download and attach images to GraphQL node
exports.createResolvers = (
jmolivas / AccountController.php
Last active Nov 28, 2019
Custom JSON Controller
View AccountController.php
namespace Drupal\jsonapi_custom\Controller;
use Drupal\Core\Controller\ControllerBase;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\jsonapi_extras\EntityToJsonApi;