Skip to content

Instantly share code, notes, and snippets.

View heitoralthmann's full-sized avatar

Heitor Althmann heitoralthmann

  • Interactive Strategies
  • Paranavaí, PR, Brazil
View GitHub Profile
@heitoralthmann
heitoralthmann / entityqueue_load.php
Created May 11, 2022 02:04
Drupal entityqueue - How to get / load items programmatically
<?php
/**
* @file
*
* Assuming that you've created a queue using the simple queue handler,
* that means a subqueue has been created automatically with the same name
* as the queue.
* Therefore, to get the (sub)queue items programatically, you can do this:
*/
@heitoralthmann
heitoralthmann / example.php
Created April 15, 2021 13:15
Drupal 8 - Migration - How to run a migration programmatically (including update and sync operations)
<?php
use Drupal\migrate\MigrateMessage;
use Drupal\migrate_tools\MigrateExecutable;
/**
* Runs a migration.
*
* @param string $migration_name
* The name of the migration to run.
@heitoralthmann
heitoralthmann / delete_ghost_file.php
Last active September 7, 2020 12:06
How to delete ghost / broken / missing fields from Drupal - Base table or view not found
<?php
/**
* Deletes ghost/broken/missing fields from the file system.
*
* I've recently run into a problem where some deleted fields were not
* completely wiped out from the system.
* This was causing the following error every time I tried to delete a
* piece of content:
*
@heitoralthmann
heitoralthmann / entity_operations.php
Created August 8, 2020 19:39
How to add new entity operations in Drupal 8
<?php
/**
* Implements hook_entity_operation().
*/
function modulename_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) {
if(in_array($entity->bundle(), ['article'])) {
$operations = array();
$operations['play'] = array(
@heitoralthmann
heitoralthmann / mymodule.install.php
Last active July 11, 2023 09:48
Drupal 8 - Resizing field with existing data - Change text field max length
<?php
//
// ATTENTION!
// This method of resizing field data TRUNCATES the information present in the field.
// This is heavily based on the solution available at https://github.com/evolvingweb/custom_field_resize
// with only a minor tweak to truncate field data before resizing the field, so we don't get an SQL error.
//
@heitoralthmann
heitoralthmann / logger.php
Created June 10, 2020 20:02
Drupal 8 watchdog logger dump variable
<?php
\Drupal::logger('some_channel_name')->warning('<pre><code>' . print_r($responseObj, TRUE) . '</code></pre>');
@heitoralthmann
heitoralthmann / migration.yml
Created April 29, 2020 14:41
Drupal 8 migrate: Using sub_process with entity_generate/entity_lookup: Looping through source field values and creating taxonomy terms for each of them.
# Looping through source field values and creating taxonomy terms for each of them (bundle_key and value_key are both required in this scenario)
field_name:
-
plugin: skip_on_empty
method: process
source: 'Source-Field-Name'
-
plugin: sub_process
process:
target_id:
@heitoralthmann
heitoralthmann / theme_name.theme.php
Created November 20, 2019 13:08
How to add css classes to the <img> tag generated by an image field (Drupal 8)
<?php
/**
* @file
* Functions to support theming in the THEME_NAME theme.
*/
/**
* Implements hook_preprocess_theme().
*/
@heitoralthmann
heitoralthmann / react_beginners_guide.md
Last active May 13, 2019 14:48
The Beginner's Guide to React / Building React Applications with Idiomatic Redux - Dan Abbramov - EggHead - Notes

The Beginner's Guide to React

Lesson 5: Validate Custom React Component Props with PropTypes

Utilizamos propTypes para tipar as props de um componente e garantir que não vão passar um tipo de dado errado, quebrando a aplicação.

Para fazer a validação de nossas props, o time do React disponibiliza uma biblioteca chamada prop-types que nos fornece uma série de funções úteis para realizar este trabalho:

ComponentName.propTypes = {
 propName: PropTypes.string,
@heitoralthmann
heitoralthmann / redux_notes.md
Last active May 9, 2019 16:46
Egghead Redux Getting Started Notes

STATE OBJECT

  • I will be representing the whole state of my application with A SINGLE STATE OBJECT.
  • This state object is read only. Every time I want to change it, I must dispatch an action.
  • The STATE is the minimum representation of data in my app.

ACTIONS

  • The ACTION is the minimum representation describing the change to that data.
  • Action objects MUST HAVE AT LEAST a type property. We better use strings for this option because it is serialisable.
  • The only way to change the state tree is by dispatching an action.
  • An action is a plain javascript object describing in the minimum way, what changed in the application.