欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

laulawyer_custom_blocks.module

<?php
 
/**
 * @file
 * Contains laulawyer_custom_blocks.module.
 */
 
use Drupal\Core\Routing\RouteMatchInterface;
 
/**
 * Implements hook_help().
 */
function laulawyer_custom_blocks_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the laulawyer_custom_blocks module.
    case 'help.page.laulawyer_custom_blocks':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('A module contains custom blocks.') . '</p>';
      return $output;
 
    default:
  }
}
 
/**
 * Implements hook_theme().
 */
function laulawyer_custom_blocks_theme() {
  return [
    'laulawyer_custom_blocks' => [
      'render element' => 'children',
    ],
  ];
}
 
 
/**
 * Implements hook_views_query_alter().
 */
function laulawyer_custom_blocks_views_query_alter(\Drupal\views\ViewExecutable $view, \Drupal\views\Plugin\views\query\QueryPluginBase $query) {
  if($view->id() == 'portfolio' &&
    !empty($view->args) &&
    $view->args[0] == "special-topic"){
    $prepend_items = $view->args[1];
    $query->setGroupOperator('OR');
    $query->setWhereGroup('OR',2);
 
    $original_order = $query->orderby;
    $query->orderby = [];
    foreach($prepend_items as $item){
      $query->addWhere(2,"node_field_data.nid",$item,"=");
      $query->addOrderby(NULL,'(node_field_data.nid='. $item .')','DESC','force_top_'.$item);
    }
 
 
    foreach($original_order as $o){
      $query->orderby[] = $o;
    }
    
  }
}
 
// $id = ;
// $entity_type = '';
// $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($id);
// var_dump($entity->uuid());
/**
 * Implements hook_update_N().
 */
function laulawyer_custom_blocks_update_8000(&$sandbox){
  $entity = \Drupal::entityManager()->loadEntityByUuid('block_content','605778af-1f4b-409e-b048-6bd4d51128a1');
  $entity->delete();
}
 
/**
 * Implements hook_update_N().
 */
function laulawyer_custom_blocks_update_8001(&$sandbox){
  $entity = \Drupal::entityManager()->loadEntityByUuid('block_content','2bc3552b-eeb0-4807-8b63-8f0aba4f4d88');
  $entity->delete();
}
 
/**
 * Implements hook_update_N().
 */
function laulawyer_custom_blocks_update_8002(&$sandbox){
  $entity = \Drupal::entityManager()->loadEntityByUuid('block_content','104fd510-0667-4b8b-b5fc-85f1b9464e1a');
  $entity->delete();
}
 
/**
 * Implements hook_update_N().
 */
function laulawyer_custom_blocks_update_8003(&$sandbox){
  $entity = \Drupal::entityManager()->loadEntityByUuid('node','d282e264-9c34-4f83-95c1-b1ef1a33106c');
  $entity->delete();
}
普通分类: