Magento 2.1のTopmenuブロックをオーバーライドしようとしていますが、そのためのガイドが見つかりません。私がここや他の場所で見つけたものはすべて、異なるフォルダ構造を使用しているように見えるバージョン2.0にのみ適用されるようです。
カスタムテーマの現在のフォルダー構造はapp/design/frontend/Vendor/theme_nameです。この中に、登録、テーマ、および作曲家のファイルと、さまざまなモジュールのフォルダー(例:Magento_Themeおよび)がありMagento_Searchます。
私が理解していることetc/di.xmlから、ここから編集された以下のようなファイルで始める必要があります:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\Theme\Block\Html\Topmenu" type="[Namespace]\[Module]\Block\Html\Topmenu" />
</config>私はまた、次のステップがBlock/Html/Topmenu.php以下のようなファイルを追加することであることも理解しています(再び上記のソースから編集):
namespace [Namespace]\[Module]\Block\Html;
class Topmenu extends \Magento\Theme\Block\Html\Topmenu
{
  protected function _addSubMenu($child, $childLevel, $childrenWrapClass, $limit)
  {
  }
}しかし、それは私がのために使うべきものを私に明らかではない[Namespace]と[Module]、あるいはどここれらのファイルを配置します。私は、ベンダーとテーマ名を使用してみました、と置いてきたetcとBlockのフォルダをapp/design/frontend/Vendor/theme_name、同様にそれらを置くことapp/design/frontend/Vendor/theme_name/Magento_Theme、に名前空間を修正Vendor\theme_name\Magento_Theme\Block\Htmlしますが、効果がありませんどちらも。
バージョン2.1でTopmenuブロックをオーバーライドするために(および他のブロックを推論するために)私が何をする必要があるかを正確に説明できる人がいれば幸いです。
補遺
Khoa TruongDinhの回答を試みましたが、影響はありませんでした。次のファイルを使用しました。
app/code/Vendor/MagentoTheme/Block/Html/Topmenu.php
<?php
namespace Vendor\MagentoTheme\Block\Html;
class Topmenu extends \Magento\Theme\Block\Html\Topmenu
{
  protected function _addSubMenu($child, $childLevel, $childrenWrapClass, $limit)
  {
    $html = '';
    if (!$child->hasChildren())
    {
      return $html;
    }
    $colStops = null;
    if ($childLevel == 0 && $limit)
    {
      $colStops = $this->_columnBrake($child->getChildren(), $limit);
    }
    // Added "test" class to test
    $html .= '<ul class="level' . $childLevel . ' test submenu">';
    $html .= $this->_getHtml($child, $childrenWrapClass, $limit, $colStops);
    $html .= '</ul>';
    return $html;
  }
}app/code/Vendor/MagentoTheme/composer.json
{
    "name": "vendor/magento-theme",
    "description": "",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "magento/framework": "100.0.*"
    },
    "type": "magento2-module",
    "version": "100.0.1",
    "license": [
        "OSL-3.0",
        "AFL-3.0"
    ],
    "autoload": {
        "files": [ "registration.php" ],
        "psr-4": {
            "Vendor\\MagentoTheme\\": ""
        }
    }
}app/code/Vendor/MagentoTheme/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\Theme\Block\Html\Topmenu" type="Vendor\MagentoTheme\Block\Html\Topmenu" />
</config>app/code/Vendor/MagentoTheme/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_MagentoTheme" setup_version="1.0.0"></module>
</config>app/code/Vendor/MagentoTheme/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
  \Magento\Framework\Component\ComponentRegistrar::MODULE,
  'Vendor_MagentoTheme',
  __DIR__
);私は、その後の内容を削除したpub/static/frontend、var/generationとvar/view_preprocessed、とMagentoのキャッシュをフラッシュしました。サブメニューには、意図した「テスト」クラスが追加されていません。
<ul class="level0 submenu ui-menu ui-widget ui-widget-content ui-corner-all" role="menu" aria-expanded="false" style="display: none; top: 52.6719px; left: 487.5px;" aria-hidden="true">...</ul>ulに「テスト」クラスを追加して、Topmenuクラスを正常にオーバーライドしたことを確認しようとしています。