I had a similar problem, where I had copied the working code from a previous block and only changed the relevant names, and when I enabled this new module... BOOOOM!!! everything crashes on any page everywhere in the entire Drupal.
After downloading the error logs from localhost/phpmyadmin I could see this:
"[Semantical Error] Couldn't find constant references_block, class Drupal\references\Plugin\Block\referencesBlock."
where: references_block is the meta-data name for my block.
it turns out that one of the quotation marks was missing.
Here is that part of the code:
ERROR CODE:
<?php
/**
* @file
*/
namespace Drupal\references\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'references' Block.
* @Block(
* id = references_block", <--------ERROR HERE! missing this: "
* admin_label = @Translation("References Block"),
* )
*/
class referencesBlock extends BlockBase {
}
FIXED CODE:
<?php
/**
* @file
*/
namespace Drupal\references\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'references' Block.
* @Block(
* id = "references_block", <-------- ERROR FIXED!
* admin_label = @Translation("References Block"),
* )
*/
class referencesBlock extends BlockBase {
// lots of code
}
How to download the error logs from localhost/phpmyadmin:
(If you're in a hurry, just read the bold text)
- Go to: localhost/phpmyadmin
- Find your Drupal database
- At the bottom of the database you should find a table called: watchdog
- Click on the table for watchdog so you see what's inside
- At the top you in the navigation you should see a tab called: SQL, click that
Now you already have a part of the query that you need, so that's easier, it should look like this:
SELECT * FROM `watchdog` WHERE 1
but you still need to change it
I used this query:
SELECT variables FROM `watchdog` ORDER BY wid DESC LIMIT 5
this will generate 5 links that is named something like this:
[BLOB - 8,8 kB]
- Start by downloading the top one, if you can't download them (I couldn't) then choose to open them in Notepad instead of downloading.
- I recommend that you use: Sublime Text 3 to open the files, that program can read almost anything, you can get it here: https://www.sublimetext.com/3
[module-root]/src/Plugin/Block/YourBlockName.php
...is it? – Commeasure