Skip to content

Instantly share code, notes, and snippets.

@drubb
drubb / BackgroundBehavior.php
Last active April 19, 2024 08:52
Example for a paragraph behavior plugin
<?php
namespace Drupal\behaviors\Plugin\paragraphs\Behavior;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\ParagraphInterface;
use Drupal\paragraphs\ParagraphsBehaviorBase;
@yusufhm
yusufhm / README.md
Last active February 25, 2024 20:34
Drupal - Remove db entries for missing files

Drupal - Remove DB entries for missing temporary files

This script aims to address the error that often appear when running Drupal cron jobs, for temporary files that have an entry in the database but not actually existing in the file system:

[error]  Could not delete temporary file "public://example_file.pdf" during garbage collection

It can be run to get a count of the files:

drush scr /path/to/remove-missing-files.php
@MustafaMagdi
MustafaMagdi / Container.php
Last active April 17, 2024 19:14 — forked from tlikai/container.php
PHP Dependency Injection Container
<?php
/**
* Class Container
*/
class Container
{
/**
* @var array
*/
@cesarmiquel
cesarmiquel / drupal-8-cheatsheet.md
Last active May 3, 2024 14:26
Drupal 8/9/10 Cheatsheet

Drupal 8 Cheatsheet

Files, Images and Media

// Load file object
$file = File::load($fid);

// Get uri (public://foo/bar/baz.png)
$uri = $file-&gt;getFileUri();
@brooke-heaton
brooke-heaton / Drupal8_views_query_alter.php
Created August 11, 2017 22:13
Alters a Drupal 8 view by adding a Left Join and Where condition
<?php
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;
/**
* Implementation of hook_views_query_alter
* @param type $view
* @param type $query
@raphaellarrinaga
raphaellarrinaga / drupal_8_twig_cheatsheet.md
Last active July 20, 2023 21:21
[Drupal 8 Twig cheatsheet] #tags: drupal8, twig, cheatsheet

Drupal 8 Twig cheatsheet

Please note I created that sheet as a personal side note/draft and not everything is fully tested. There could be errors or better things to do. So if you spot something wrong or something that can be improved, feel free to comment below and I will do the changes.

Getting Drupal 8 field values in Twig

Image path: {{ file_url(content.field_name['#items'].entity.uri.value) }}

@codedokode
codedokode / Тестирование.md
Last active April 25, 2024 20:24
Автоматизированное тестирование

Автоматизированное тестирование

Обычно после написания кода его проверяют. Если речь о какой-то функции, то можно написать простой скрипт, который будет вызывать ее с разными аргументами, и смотреть, что она вернет. Если вы сделали сайт или приложение, то вы открываете его, жмете ссылки и кнопки, проверяете что все отображается верно. Это называется ручное тестирование или QA (Quality Assurance — контроль качества) — человек проверяет работу программы. Если мы попробуем автоматизировать этот процесс, и написать программу, которая проверяет правильность другой программы, то это называется автоматизированное тестирование.

Главный плюс автоматических тестов — то, что они выполняются намного быстрее, чем ручное тестирование, и вам не надо тратить на это свое время (или время тестировщика). Это позволяет запускать их хоть после каждого изменения в коде.

Также, тесты позволяют «защитить» написанный код. Если кто-то в команде (или вы сами) нечаянно «сломал» ваш код, тесты это обнаружат и укажут, что именн

@codedokode
codedokode / js-task-1.md
Last active March 4, 2024 12:35
Задания на яваскрипт (простые)
@juampynr
juampynr / mymodule.info
Last active June 9, 2023 21:53
Drupal 7 Views 3 custom field handler
dependencies[] = ctools
; Views Handlers
files[] = views/mymodule_handler_handlername.inc
@ecorson
ecorson / drush_admin_create
Created April 3, 2012 14:43
Add admin user via Drush
drush user-create adminuser --mail="adminuser@uiowa.edu" --password="UserPw"; drush user-add-role "administrator" adminuser