2

I've followed the tutorial to create a custom block from https://www.drupal.org/node/2101565

My module installed fine and I can see the block in the list of available Blocks for placing, but as soon as I click "Place Block" I just see the ajax loader for about 1 second and then nothing happens, the dialog stays open and my block does not get placed. Cleared the cache etc. didn't help, the error log does not show any available messages.

My src/Plugin/Block/TestBlock.php file:

<?php
namespace Drupal\test_block\Plugin\Block;

use Drupal\block\BlockBase;

/**
 * Provides a 'Demo' block.
 *
 * @Block(
 *   id = "test_block",
 *   admin_label = @Translation("A Test Block"),
 * )
 */
class TestBlock extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {
    return array(
      '#markup' => $this->t('Hello, World!'),
    );
  }
}
?>

Drupal 8.1.1

1
  • Share your code so that someone would be able to help you. May 26, 2016 at 8:37

2 Answers 2

7

You have an error in your block that causes a fatal error or exception.

Right click and open the place block in a new window and/or check your error logs.

3
  • Thanks for the hint, opening in a new windows shows only an error 500, i'll check the server settings. However, the error logs of drupal do not show any entry. Also, I really copy&paste the tutorial content.
    – TSGames
    May 26, 2016 at 19:26
  • Thanks, found it, the use import was wrong. Must have copied it from a wrong example. However, it's strange that there's nothing in the Drupal error logs.
    – TSGames
    May 26, 2016 at 20:20
  • 2
    Drupal doesn't log fatal errors. When developing, always enable display_errors in php.ini and display errors in Drupal. See example.settings.local.php.
    – Berdir
    May 26, 2016 at 21:56
0

I ran into this and it ended up being an error in the Annotation syntax. Specifically the opening comment of the annotation had characters after the "/**" Make sure your block annotation starts like this:

 /**
  * short description of block
  *
  * @Block(
  *   id = "custom_module_block_machine_name",
  *   admin_label = @Translation("Admin interface Label"),
  *   category = @Translation("Custom Module or Category Name")
  * )
  */

https://www.drupal.org/node/1882526

Not the answer you're looking for? Browse other questions tagged or ask your own question.