Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesus Manuel Olivas jmolivas

View GitHub Profile
@jmolivas
jmolivas / DefaultController.php
Last active Oct 8, 2021
Drupal 8 example: How to render a Twig template and load a CSS file from a Controller
View DefaultController.php
<?php
namespace Drupal\acme\Controller;
use Drupal\Core\Controller\ControllerBase;
class DefaultController extends ControllerBase
{
/**
@jmolivas
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() {
SpreadsheetApp.getUi()
.createMenu('Scripts')
.addItem('Build', 'build')
.addToUi();
}
@jmolivas
jmolivas / inject-service-drupal-8.md
Last active Jul 28, 2020
Inject a service from the service container
View inject-service-drupal-8.md

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
jmolivas / crawl-drupal-jsonapi.sh
Created Jun 12, 2020 — forked from KalleVuorjoki/crawl-drupal-jsonapi.sh
Script to crawl Drupal JSON:API endpoint to local filesystem.
View crawl-drupal-jsonapi.sh
#!/bin/bash
##
# Script to crawl Drupal JSON:API endpoint to local filesystem.
#
# Assumes endpoint to be /jsonapi and uses basic auth.
#
# Requirements:
# ag - https://github.com/ggreer/the_silver_searcher
# jq - https://github.com/stedolan/jq
View gatsby-node.js
exports.createResolvers = ({ actions, getCache, createNodeId, createResolvers }) => {
const { createNode } = actions
createResolvers({
Drupal_MediaImage: {
gatsbyImageFile: {
type: `File`,
resolve(source) {
return createRemoteFileNode({
@jmolivas
jmolivas / install-fish.sh
Last active May 1, 2020
Improve your shell with fish and oh my fish.
View install-fish.sh
brew install fish
View MyRestResource.php
<?php
/**
* @file
* Contains \Drupal\my_module\Plugin\rest\resource\MyRestResource.
*/
namespace Drupal\my_module\Plugin\rest\resource;
use Drupal\Core\Session\AccountProxyInterface;
@jmolivas
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 = (
{
actions,
cache,
createNodeId,
createResolvers,
View 2020-events.md
@jmolivas
jmolivas / AccountController.php
Last active Nov 28, 2019
Custom JSON Controller
View AccountController.php
<?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;