Issue While Assigning Custom Block to Block Layout or Layout Builder
Error Message:
Drupal\Component\Plugin\Exception\PluginException: No plugin ID specified for component with "XXXXXX" UUID in Drupal\layout_builder\SectionComponent->getPluginId() (line 218 of D:\xamp\htdocs\coin\web\core\modules\layout_builder\src\SectionComponent.php).
This error occurs because the plugin ID and definition for the custom block are not properly specified. Plugin IDs are unique identifiers used in Drupal to define new components like block types, field types, menu items, and more.
Solution:
To resolve this issue, ensure that the plugin ID and definition are correctly added to the __construct() function of your custom block code.
Ex :
namespace Drupal\module_name\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Description
*
* @Block(
* id = "Id of the block",
* admin_label = @Translation("Block Name"),
* )
*/
class block_class extends BlockBase {
/**
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
public function build() {
}
Adding this ensures that the plugin is correctly registered and avoids the PluginException error.
Comments
Post a Comment