#drupal #migration #drupal-7 #drupal-8 #drupal-modules
Вопрос:
У меня есть блок drupal 7, который управлял несколькими разными страницами в родительском «/продукт/%», где % является идентификатором элемента. Другая страница — «продукт/%/сводка». Единственные другие блоки, которые я перенес, состоят из одного файла шаблона с одним возвращаемым массивом.
Drupal 7
код в модуле prodcut_page.:
function product_page_menu() { $items = array(); $items['product/%'] = array( 'title' =gt; 'Product Page', 'page callback' =gt; 'prodcut_make_table', 'page arguments' =gt; array(1), 'access callback' =gt; TRUE, ); $items['product/%/detail'] = array( 'title' =gt; 'Detail', 'page callback' =gt; 'product_get_detail', 'page arguments' =gt; array(1), 'access callback' =gt; 'test_detail', 'access arguments' =gt; array(1), 'type' =gt; MENU_LOCAL_TASK, 'weight' =gt; -10, );
Drupal 8
кодовый крючок в модуле prodcut_page.module
lt;?php /** * Implements hook_menu() D8 */ use DrupalCoreDatabaseDatabase; function yearly_count_theme($existing, $type, $theme, $path){ return array( 'product_page' =gt; 'product-page.html.twig' array( 'variables' =gt; array( 'var1' =gt; '', ), ), 'detail_page' =gt; 'detail-page.html.twig' array( 'variables' =gt; array( 'var2' =gt; '', ), ), ); }
код в src/Plugin/Block/ProductpageBlock.php
lt;?php namespace Drupalproduct_pagePluginBlock; use DrupalCoreBlockBlockBase; use DrupalCoreBlockBlockPluginInterface; /** * Provides a 'product pages' Block. * * @Block( * id = "product_page", * admin_label = @Translation("Product Pages"), * category = @Translation("Product Pages"), * ) */ class ProductpageBlock extends BlockBase implements BlockPluginInterface { /** * {@inheritdoc} */ public function build() { $items['product/%'] = array( '#title' =gt; 'Product Page', '#theme' =gt; 'product_page', '#var1' =gt; product_make_table(), ); $items['product/%/detail'] = array( 'title' =gt; 'Summary', '#theme' =gt; 'product_page', '#var2' =gt; product_get_detail(), ); return $items; } }