shortify-1.0.9/shortify.module

shortify.module
<?php

use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Routing\RouteMatchInterface;

function shortify_preprocess_breadcrumb(&$variables) {
    $node = Drupal::routeMatch()->getParameter('node');

    if (is_object($node) && $variables['breadcrumb']) {
        $variables['breadcrumb'][] = [
            'text' => $node->getTitle(),
            'url' => $node->toUrl()->toString(),
        ];
        $variables['#cache']['contexts'][] = 'url';
    }
}

function shortify_system_breadcrumb_alter(Breadcrumb $breadcrumb, RouteMatchInterface $route_match) {
    if (!isset($route_match) && $node = $route_match->getParameter('node')) {
        $breadcrumb->addCacheableDependency($node);
    }
}

function shortify_preprocess_node(&$vars) {
    if (isset($vars['elements']['body'][0]['#type']) && $vars['elements']['body'][0]['#type'] === 'processed_text' && isset($vars['elements']['body'][0]['#text'])) {

        $text = $vars['elements']['body'][0]['#text'];
        $match = '';
        preg_match('/ps_cache="([^"]+)"/', $text, $match, PREG_OFFSET_CAPTURE);

        if (isset($match[1]) && $match[1][0] === "false") {
            $vars['#cache']['max-age'] = 0;
        }
    }
}

function shortify_preprocess_block(&$vars) {
    if (isset($vars['elements']['content']['body'][0]['#type']) && $vars['elements']['content']['body'][0]['#type'] === 'processed_text' && isset($vars['elements']['content']['body'][0]['#text'])) {

        $text = $vars['elements']['content']['body'][0]['#text'];
        $match = '';
        preg_match('/ps_cache="([^"]+)"/', $text, $match, PREG_OFFSET_CAPTURE);

        if (isset($match[1]) && $match[1][0] === "false") {
            $vars['#cache']['max-age'] = 0;
        }
    }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc