Skip to content

Instantly share code, notes, and snippets.

@jmolivas
jmolivas / script.js
Last active February 6, 2021 16:21
Trigger Netlify build from a Google Spreadsheet
# 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();
}

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/
@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
function name_theme_preprocess_page() {
// ...
$variables['social_networks'] = theme_get_setting('social_networks', 'name_theme');
}
@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 / 2018-talks.md
Last active January 3, 2018 22:17
Planned sessions for events during 2018

Planned sessions for events during 2018

Improving Drupal 8 development workflow

Drupal 8 has changed a lot and the process of creating, building, testing and deploying a site is not the exception.

During this session, you will understand the process of creating, building, testing and deploying Drupal 8 sites, and learn which tools you can use to improve your local development workflow and reduce project setup and onboarding time, implement automated analysis tools for code review, code coverage and finally how to build an artifact and deploy your project.

Writing CLI Commands for Drupal 8

@jmolivas
jmolivas / module_name.install
Last active December 4, 2017 16:52
Change the text field maximum length
<?php
/**
* Update the length of a text field which already contains data.
*
* @param string $entity_type_id
* @param string $field_name
* @param integer $new_length
*/
function _module_change_text_field_max_length ($entity_type_id, $field_name, $new_length) {
@jmolivas
jmolivas / module_name.install
Created November 24, 2017 18:41
Update field data table and configuration storage object.
<?php
/**
* Update field data table and configuration storage
*/
function _update_field_data(
$entityType,
$field,
$valueMapping,
@jmolivas
jmolivas / module_name.install
Last active November 9, 2017 20:25
Update all of the instances of a field in a Drupal 8 database
<?php
function _update_table_field($fieldName, $valueMapping) {
$schema = \Drupal::database()->schema();
$tables = $schema->findTables('%');
foreach ($tables as $table) {
if ($schema->fieldExists($table, $fieldName)) {
foreach ($valueMapping as $originalValue => $newValue) {
echo sprintf(
'Updating table %s and field %s from %s to %s',
@jmolivas
jmolivas / ._README.md
Last active January 2, 2018 15:57
Basic docker configuration for drupal projects

Basic docker configuration for drupal projects

Extra steps

  1. If not using DrupalConsole you will need to add the vlucas/phpdotenv dependency to load the .env file. You can do that using composer:
composer require vlucas/phpdotenv
  1. Add the TRAEFIK_HOST value to /etc/hosts