2016-04-30 6 views
0

Ich stieß auf ein Problem beim Erstellen eines benutzerdefinierten Blocks. Es gibt andere Blöcke innerhalb desselben Moduls, die hinzugefügt werden können und gut funktionieren.Drupal 8 benutzerdefinierte Block zeigt in Block Liste, kann aber nicht hinzugefügt werden

Hier ist der Code (Dateiname TourLink.php in/modules/custom/custom_blocks/Plugin/Block/ist):

<?php 
/** 
* Provides a block that links to /tour 
* 
* @Block(
* id = "tour_link", 
* admin_label = @Translation("Tour Link"), 
*) 
*/ 

namespace Drupal\custom_blocks\Plugin\Block; 

use Drupal\Core\Block\BlockBase; 

class TourLink extends BlockBase { 
    /** 
    * {@inheritdoc} 
    */ 
    public function build() { 
    $output = ' 
    <span>test</span> 
    '; 

    return array(
     '#type' => 'markup', 
     '#markup' => $output, 
    ); 
    } 

} 

Vielen Dank im Voraus!

+0

Klassenanmerkungen gehen an _das Ende des Dokumentationsblocks unmittelbar vor der Klassendeklaration_ (siehe [Anmerkungen] (https://api.drupal.org/api/drupal/core%21core.api.php/group/annotation/ 8.2.x)). Ich bin mir nicht sicher, aber vielleicht ist das wirklich wichtig. –

+0

Danke, aber das war es nicht. –

Antwort

0

Das Umbenennen der Klasse (und der Datei natürlich) zu LinkToTourBlock behob das Problem. Warum, ich weiß es nicht. Auch TourLinkBlock funktionierte nicht. Sooo komisch!

Verwandte Themen