Skip to content

Instantly share code, notes, and snippets.

@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 {
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`
<?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;
@jmolivas
jmolivas / _README.md
Last active November 1, 2019 14:18
Convert entity files as media using Drupal 8

Convert entity files as media using Drupal 8

  • Install Drupal Console

  • Copy content of add-file-image-as-media-image.php to console/snippet/

  • Execute drupal console snippet command

drupal snippet --file=console/snippet/add-file-image-as-media-image.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 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'
]);
@jmolivas
jmolivas / try-umami-sqlite.yml
Last active September 14, 2019 20:19
Drupal 8.5 umami installation using DrupalConsole
# Requires
# - DrupalConsole Launcher
# - Git
# - Composer
# - Sqlite
#
# How to use:
# copy the content of this gist to a new file name it as ~/.console/chain/try-umami-sqlite.yml
#
# Execution:
@jmolivas
jmolivas / README.md
Last active August 5, 2019 20:01
Render a form on a page via a Controller on Drupal8.

Create file at ~/console/chain/generate-controller-form-render.yml containing:

command:
  name: 'generate:controller:form:render'
  description: 'Controller + Form generator'
commands:
  - command: 'generate:module'
    options:
        module: example
@jmolivas
jmolivas / readme.md
Last active June 10, 2019 22:18
Automate DrupalConsole release process

Automate DrupalConsole release process

This script run the following tasks on multiple repos from the CLI.

  • Creates a new tag.
  • Push new created tag.
  • Create a new release.
  • Build the phar file. (only for drupal-console-launcher)
  • Upload the phar file (only for drupal-console-launcher)

To execute this proces is required to install

Convert body fields from HTML to Markdown

  • Install Drupal Console

  • Install PHP dependency

composer require league/html-to-markdown
  • Copy content of convert-html-markdown.php to console/snippet/