load_block_on_ajax-8.x-1.0/load_block_on_ajax.module

load_block_on_ajax.module
<?php

/**
 * Implements hook_preprocess_block().
 */
function load_block_on_ajax_preprocess_block(&$variables) {

    $variables['content'] = $variables['elements']['content'];

    if (isset($variables['elements']['content']['#title']) && !empty($variables['configuration']['label_display'])) {
        $variables['label'] = $variables['elements']['content']['#title'];
    }

    $var = [];
    $config = \Drupal::config('load_block_on_ajax.settings');
    if( $config->get('load_block_on_ajax_var') != '' ) {
        $var = unserialize( $config->get('load_block_on_ajax_var') );
    }

    if( array_key_exists($variables['elements']['#id'], $var) ) {
        $current_path = \Drupal::service('path.current')->getPath();
        $arr_path = explode( '/', $current_path );
        if( 'load-block-on-ajax' != $arr_path[1] ) {
            $variables['content'] = '';
        }
        $variables['#cache']['max-age'] = 0;
        $variables['attributes']['id'] = 'load-block-on-ajax-wrapper--' . $variables['elements']['#id'];
    }

}

/**
 * Implements hook_page_attachments().
 */
function load_block_on_ajax_page_attachments(array &$page) {
    $page['#attached']['library'][] = 'load_block_on_ajax/load_block_on_ajax';
}

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

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