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
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Испытание: другой вариант главной</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="page-header">
<div class="logo"><img src="logo.svg" width="90" height="90" alt="Cat Energy">
@Seorusus
Seorusus / breakthrough.theme
Last active February 25, 2020 10:07
If needed override form element by name, add to function breakthrough_theme_suggestions_alter(array &$suggestions, array $variables, $hook)
if (in_array($hook, ['input', 'form_element'])) {
if (
isset($variables['element']['#name']) &&
'ai_expertise' === $variables['element']['#name']
) {
$suggestions[] = $hook . '__' . str_replace('-', '_', $variables['element']['#name']);
}
@Seorusus
Seorusus / ChallengeOverviewController.php
Last active February 12, 2020 08:56
Render views display by Argument Challenge ID
<?php
/**
* Returned list of team in current phase.
*/
public function getView() {
$challenge_id = $this->challenge->id();
return views_embed_view('registration_phase', 'block_1', $challenge_id);
}
@Seorusus
Seorusus / pfbreakthrough_profile.install
Created February 11, 2020 10:46
Delete field value by hook_update
<?php
/**
* Implements hook_update_N().
*/
function pfbreakthrough_profile_update_8005() {
$database = \Drupal::database();
if ($database->schema()->tableExists('user__field_color')) {
$database->truncate('user__field_color')->execute();
}
@Seorusus
Seorusus / SettingsController.php
Last active February 10, 2020 16:14
Set variable using view_mode template 'compact'
<?php
namespace Drupal\internal_dashboard\Controller;
use Drupal\user\Entity\User;
/**
* The controller for SettingsController.
*/
class SettingsController extends ManageChallengesController {
@Seorusus
Seorusus / User.php
Created February 7, 2020 17:04
Get First letter of the string field
<?php
/**
* Returns a first letter of the last name of a User.
*
* @return string
* Last letter of the first name of a User.
*/
public function getLastLetterFirstName(): string {
return (string) substr($this->get('field_last_name'), 0, 1);
}
@Seorusus
Seorusus / User.php
Last active February 7, 2020 13:18
Random value selection in the list text field
<?php
/**
* {@inheritdoc}
*/
public function preSave(): void {
$this->entity->activate();
if ($this->entity->isNew()) {
if ($this->entity->hasField('field_color')) {
$field_color = $this->entity->get('field_color');
$allowed_values = $field_color->getFieldDefinition()->getSetting('allowed_values');
@Seorusus
Seorusus / YourResourcesController.php
Last active February 7, 2020 13:03
Вывести все ноды определенного типа
<?php
$nids = \Drupal::entityQuery('node')->condition('type','your_resources')->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
@Seorusus
Seorusus / YourResourcesController.php
Last active February 7, 2020 13:04
Получение значения поля через id ноды
<?php
/**
* Get field_related_documents field.
*
* @return string |null
*/
protected function getDocLink() {
$id = \Drupal::entityQuery('node')
->condition('type', 'your_resources')
->execute();
@Seorusus
Seorusus / test.theme
Created January 21, 2020 15:10
добавление таймзоны к полю date
function pfallabouth_theme_preprocess_node(array &$variables) {
if ($variables['node']->getType() === 'event') {
$node = \Drupal::routeMatch()->getParameter('node');
$timezone = Drupal::currentUser()->getTimeZone();
/* @var Drupal\Core\Datetime\DateFormatter $formatter */
$formatter = \Drupal::service('date.formatter');
$time_user = $formatter->format((int) strtotime($node->get('field_date')->getString()), 'custom', 'd M Y | H:i A', $timezone);
$variables['event_date_user'] = $time_user;
}
}