Skip to content

Instantly share code, notes, and snippets.

View Seorusus's full-sized avatar
🏠
Working from home

Oleg Kreminsky Seorusus

🏠
Working from home
View GitHub Profile
function dd($data) {
echo '<pre>';
var_dump($data);
echo '</pre>';
die();
}
@Seorusus
Seorusus / euroradio_paragraphs.module
Created September 13, 2022 10:54
The paragraph customization
<?php
/**
* @file
* Defines Drupal hooks for euroradio_paragraphs module.
*/
use Drupal\Component\Serialization\Json;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
@Seorusus
Seorusus / EuroradioProgramEpisodes.php
Created September 13, 2022 10:34
A handler to provide field "euroradio_program_episodes" to views
<?php
namespace Drupal\euroradio_program\Plugin\views\field;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\euroradio_player\PlayerRenderHelper;
use Drupal\file\Entity\File;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
@Seorusus
Seorusus / prevalat_checkout.module
Created September 13, 2022 10:11
Custom checkout for Prevalat
<?php
/**
* @file
* Contains prevalat_checkout.module.
*/
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_product\Entity\Product;
@Seorusus
Seorusus / FormBuildHelper.php
Last active June 15, 2022 10:39
Перемесить чекбокс статус в группу options
public function nodeFormAlter(array &$form, FormStateInterface $formState): void {
$node = $formState->getFormObject()->getEntity();
if (isset($form['status'])) {
$form['status']['#group'] = 'options';
}
}
@Seorusus
Seorusus / euroradio_api_yandex.module
Created January 31, 2022 16:25
Удаление дубликатов из views при использовании relationship
/**
* Implements hook_views_query_alter() for restrict duplicated nodes.
*/
function euroradio_api_yandex_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
switch($view->storage->id()){
case 'yandex_rss';
// $query->addField('entity_type', 'id', '', ['function' => 'groupby']);
// $query->addGroupBy('entity_type.id');
$query->addField('node_field_data', 'nid', '', ['function' => 'groupby']);
/**
* {@block}
*/
public function build() {
$config = $this->getConfiguration();
$text = $this->t('@Hero', ['@Hero' => $config['hero_banner_block_settings']]);
$build = [
'#theme' => 'hero_banner',
'#first' => $text,
];
@Seorusus
Seorusus / porto_sub.theme
Last active August 20, 2021 16:24
Set query argument from url using preprocess_views_view
function porto_sub_preprocess_views_view(&$variables) {
$variables['current_url'] = \Drupal::request()->query->get('blog');
}
@Seorusus
Seorusus / script.js
Created May 6, 2021 19:26
Drupal Добавление класса к элементу, если элемент выбран
// Add active-item class if element checked.
$('.form-item-field-category-tid-i18n input').each(function() {
if($(this).is(":checked")) {
$(this).parent().addClass('active-item');
}
});
@Seorusus
Seorusus / paragraph---list-cards-one-item--default.html.twig
Last active May 6, 2021 19:30
Drupal Использование поля link в качестве href="" атрибута ссылки
{% block paragraph %}
<div{{ attributes.addClass(classes) }}>
{% block content %}
<a href="{{ content.field_card_link.0['#url'] }}">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 lo-use-item fadeIn wow animated animated animated" style="visibility: visible;">
<span class="bg-animate">
{{ content|without("field_card_link") }}
</span>
</div>
</a>