Skip to content

Instantly share code, notes, and snippets.

@jmolivas
jmolivas / crawl-drupal-jsonapi.sh
Created June 12, 2020 19:20 — forked from KalleVuorjoki/crawl-drupal-jsonapi.sh
Script to crawl Drupal JSON:API endpoint to local filesystem.
#!/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
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 February 7, 2020 22:52
Drupal + GraphQL + Gatsby code snippets
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,
@jmolivas
jmolivas / AccountController.php
Last active November 28, 2019 23:07
Custom JSON Controller
<?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;
<?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;
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 November 6, 2019 19:42
used for demonstration purposes
export const query = graphql`
query($slug: String!) {
site {
siteMetadata {
domain
}
}
allSiteSettingEntitySite {
edges {
node {
<?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 September 24, 2019 17:10
Code snippet to merge several paragraphs fields into a single field.
<?php
$nodeManager = \Drupal::entityTypeManager()->getStorage('node');
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'type' => 'landing'
]);