Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesus Manuel Olivas jmolivas

View GitHub Profile
@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 / 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;
View MetatagEnhancer.php
<?php
declare(strict_types = 1);
namespace Drupal\module_name\Plugin\jsonapi\FieldEnhancer;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Utility\Token;
use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase;
View blog-page-index.js
import React from 'react'
import { StaticQuery, graphql } from 'gatsby'
import Layout from '../components/templates/layout'
import Home from '../components/templates/home'
const dateFormat = require('date-fns/format')
const IndexPage = () => (
<StaticQuery
query={graphql`
@jmolivas
jmolivas / page-template-grahql-query.js
Created Nov 6, 2019
used for demonstration purposes
View page-template-grahql-query.js
export const query = graphql`
query($slug: String!) {
site {
siteMetadata {
domain
}
}
allSiteSettingEntitySite {
edges {
node {
View AliasLinkEnhancer.php
<?php
namespace Drupal\module_name\Plugin\jsonapi\FieldEnhancer;
use Drupal\Core\Url;
use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase;
use Shaper\Util\Context;
/**
* Use alias for internal link field value.
@jmolivas
jmolivas / merge_landing_paragraphs.php
Created Sep 24, 2019
Code snippet to merge several paragraphs fields into a single field.
View merge_landing_paragraphs.php
<?php
$nodeManager = \Drupal::entityTypeManager()->getStorage('node');
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'type' => 'landing'
]);