Skip to content

Instantly share code, notes, and snippets.

View Oleksii909's full-sized avatar
👍
Focusing on drupal

Oleksii Bondarenko Oleksii909

👍
Focusing on drupal
View GitHub Profile
/**
* Implements hook_theme_suggestions_HOOK_alter() for block templates.
*/
function custom_theme_suggestions_node_alter(array &$suggestions, array $variables) {
$element = $variables['elements'];
// Add template suggestions based on the current view mode.
$node = $variables['elements']['#node'];
$suggestions[] = 'node__' . $variables['elements']['#view_mode'];
$suggestions[] = 'node__' . $node->bundle() . '__' . $variables['elements']['#view_mode'];
}
@Oleksii909
Oleksii909 / Blocks.md
Created December 12, 2020 16:55 — forked from bdlangton/Blocks.md
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
// Enable Devel module and go to /devel/php
$nodes = \Drupal::entityQuery("node")
->condition('created', strtotime('-30 days'), '<=')
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
// $entities = $storage_handler->loadMultiple(); // Delete ALL nodes.
$entities = $storage_handler->loadMultiple($nodes);
$storage_handler->delete($entities);
@Oleksii909
Oleksii909 / hints.md
Created December 4, 2020 01:05
Remove all docker containers

stop all containers: docker kill $(docker ps -q)

remove all containers docker rm $(docker ps -a -q)

remove all docker images docker rmi $(docker images -q)

Images skilldlabs/php:73-fpm-dev and :74-fpm-dev updated you could use docker run --rm -it skilldlabs/php:74-fpm-dev php -dzend_extension=xdebug -r'xdebug_info();' to check the v3 used all Drupal 9.1.0 release will get delay (probably second week of Dec) The committer team discussed this situation yesterday and we've decided the minor release will now be the second week of December, which will give us more time to deal with PHP's release, corresponding upstream updates, and the latest symfony minor.

The upgrade path is https://xdebug.org/docs/upgrade_guide

@Oleksii909
Oleksii909 / gist:fa9b1eb563a199836bb53aac17a45199
Last active November 14, 2020 10:21
@trigger_error('Support for IE Conditional Comments is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3102997', E_USER_DEPRECATED);
<?php
$tags['link'] = [HtmlTag::preRenderConditionalComments($element), '<link />' . "\n"];
// Conditional link.
$element = [
'#tag' => 'link',
'#browsers' => [
'IE' => TRUE,
'!IE' => FALSE,
],
<?php
/**
* {@inheritdoc}
*/
protected function assertEntityInstanceFieldMarkup($expected_field_attributes) {
if (func_num_args() === 4) {
$expected_field_attributes = func_get_arg(3);
@trigger_error('Calling ' . __METHOD__ . '() with 4 arguments is deprecated in drupal:9.1.0 and will throw an error in drupal:10.0.0. See https://www.drupal.org/project/drupal/issues/3037436', E_USER_DEPRECATED);
}
parent::assertEntityInstanceFieldMarkup($this->replaceLayoutBuilderFieldIdKeys($expected_field_attributes));
<?php
$js_match_field_element_attributes = <<<JS
function () {
var expectations = $expected_field_attributes_json;
var entityCollection = Drupal.quickedit.collections.entities;
var entityModel = entityCollection.get('$entity_page_id');
return entityModel.get('fields').reduce(function (result, fieldModel) {
var fieldID = fieldModel.get('fieldID');
var element = fieldModel.get('el');
var matches = element.webkitMatchesSelector(expectations[fieldID]);