Skip to content

Instantly share code, notes, and snippets.

Avatar

Isaac Bigsby Trogdon IsaacBigsbyTrogdon

View GitHub Profile
View composer-update-drupal.md

Update drupal with composer

composer update drupal/core "drupal/core-*" --with-all-dependencies

or without drupal/core-recommended (deprecated)

composer update drupal/core --with-dependencies

@IsaacBigsbyTrogdon
IsaacBigsbyTrogdon / drush_delete_entities_of_type.php
Last active Aug 31, 2021
Drupal delete entities of type with drush
View drush_delete_entities_of_type.php
<?php
drush eval '$entity_type = "shortcut"; $storage_handler = \Drupal::entityTypeManager()->getStorage($entity_type); $storage_handler->delete($storage_handler->loadMultiple(\Drupal::entityQuery($entity_type)->execute()));'
View Mysql return tables by size.txt
SELECT
TABLE_NAME AS `Table`,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "my_database_name"
ORDER BY
(DATA_LENGTH + INDEX_LENGTH)
DESC;
@IsaacBigsbyTrogdon
IsaacBigsbyTrogdon / DrupalComputedField.php
Last active Aug 19, 2021
Drupal computed field example
View DrupalComputedField.php
<?php
namespace Drupal\my_module\Fields;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
use Drupal\Core\Url;
class MenuTeasers extends EntityReferenceFieldItemList {
View ddev-cheatsheet.md

DDEV Commands Cheatsheet

Enable NFS

curl -O https://raw.githubusercontent.com/drud/ddev/master/scripts/macos_ddev_nfs_setup.sh && chmod +x macos_ddev_nfs_setup.sh && ./macos_ddev_nfs_setup.sh
nv ~/.ddev/global_config.yaml
# add => nfs_mount_enabled: true

Reset container

@IsaacBigsbyTrogdon
IsaacBigsbyTrogdon / README-phpcs-drupal-ddev-pre-commit.md
Last active Aug 11, 2021
Add PHP Code Sniffer for Drupal DDEV with git hook
View README-phpcs-drupal-ddev-pre-commit.md

Add PHP-Codesniffer & DrupalStandards

ddev ssh
composer require drupal/coder --dev
composer require dealerdirect/phpcodesniffer-composer-installer --dev
composer require loomgmbh/git-hooks-pre-commit-ddev --dev

Set PHPCS config

@IsaacBigsbyTrogdon
IsaacBigsbyTrogdon / pre-commit
Created Aug 9, 2021 — forked from bserem/pre-commit
Run phpcs in ddev with Drupal standard on pre-commit.
View pre-commit
#!/usr/bin/php
<?php
/**
* @file
* A Git pre-commit hook script to check files for PHP syntax errors and Drupal
* coding standards violations. Requires phpcs and Coder Sniffer:
*
* @see https://drupal.org/node/1419988
*
View DrupalBlockCachePerPage.php
<?php
namespace Drupal\test_module\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'Test block' Block.
*
* @Block(
View array_map_with_keys.php
<?php
// array_map with $key => $value
return array_map(function($key, $value) {
return [$key => $value];
}, array_keys($my_array), $my_array);
@IsaacBigsbyTrogdon
IsaacBigsbyTrogdon / hook_update_delete_content()
Created Jun 3, 2020
Delete and manipulate drupal entities in hook_update_N().
View hook_update_delete_content()
<?php
/**
* Reset fields from dev.
*
* @param $sandbox
*/
function loom_solr_multisite_update_8010(&$sandbox) {
/** @var MultisiteSearchService $multisite */
$multisite = Drupal::service('loom.solr_multisite.utility');