2

I've created my own module in drupal 8. I also created block in my module. I tryied to add my custom block (which is type of custom form) to view. But when I am trying to add custom block in view, its not appearing in the list. Block is only appearing in block layout. What is wrong or is there other way of adding custom block from module to your view in drupal 8?

<?php
/**
 * @file
 * Contains \Drupal\reviewhelper\Plugin\Block\ReviewHelperBlock.
 */
namespace Drupal\reviewhelper\Plugin\Block;

use Drupal\reviewhelper\Form;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a 'ReviewHelper' Block
 *
 * @Block(
 *   id = "ReviewHelper",
 *   admin_label = @Translation("Review helper block"),
 *   category = @Translation("Custom Blocks"),
 * )
 */
class ReviewHelperBlock extends BlockBase {
  /**
   * {@inheritdoc}
   */
  public function build() {
    $form = \Drupal::formBuilder()->getForm('Drupal\reviewhelper\Form\ReviewHelperPush');
    return $form;
  }
}
  • It's not clear in this context what you mean by "view", do you mean a view from the Views module or something else? – Cottser Jun 22 '15 at 14:51
  • Yes Cottser I meant views module. The problem itself is to how add custom block to view in views module. – Anton Vlasenko Jun 22 '15 at 19:55
2

There are two different "block things". Actually, three.

  1. First, there are block plugins. That's code, that's what you have. It's the thing you select on the block layout page. It's not something that you can list with views (Well, theoretically, it would be possible, but you would have to write a views query plugin that queries plugins.)

  2. Then, there block config entities. That's a plugin + configuration, a block placement.

  3. Last, there are custom blocks or content blocks. Those are content entities, similar to nodes with different types, fields and so on. Those are the user-created data. Each of them is exposed on the block layout page as a plugin derivate. There's one plugin class for them and then there are derivates for each content entity. Those are the things you can list with views. Only those.

Everything is connected, you can create custom/content blocks, which are exposes as a block plugin, which is then placed and becomes a block config entity. But they're all different things.

  • Berdir can you explain/elaborate about views query plugin that queries plugins in drupal 8? – Anton Vlasenko Jun 22 '15 at 19:58
  • Not really, no. It doesn't exist, it's just an idea. And it very likely wouldn't allow you to do what you have in mind. Maybe you're looking for something like drupal.org/project/page_manager, It's not clear to me at all why you'd want to add a block plugin to a view and how. – Berdir Jun 22 '15 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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