Skip to main content

Plugin

Displaying 1 - 2 of 2

Custom Block: Create fast and simple

Blocks are individual pieces of your site’s web page layout. They are placed inside the regions of your theme, and can be created, removed, and rearranged in the Block layout (admin/structure/block) administration page.

Examples of blocks include the Who’s online listing, the main navigation menu, and the breadcrumb trail. The main page content is also a block.

<?php

namespace Drupal\basic_module\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Block annotation
 * 
 * @Block(
 *      id = "basic_block",
 *      admin_label = @Translation("Basic Block"),
 * )
 */
class BasicBlock extends BlockBase {
   /**
     * {@inheritDoc}
     */
    public function build() {
        $markup = '';
        $markup .= '<div>';
        $markup .= '    <p>Anything can come here: code, variables, html, etc.  </p>' ;
        $markup .= '</div>';
        return [
            '#type' => 'markup',
            '#markup' => $markup,
        ];
    }    
    
} // end of class

Advance Examples Which actually needed

This article is based on the O'Reilly article which is relevant to Drupal7 and some of it for Drupal8, but drupal did a lot of modifications since then, and I believe it's a good place to start with, but still should be modified to Drupal9 and on. from time to time I will fix this article and update it according to the last drupal version, you are all invited to send me remarks and suggestions.

These examples, I believe are most needed for the more advanced Drupal backend developer.

My development strategy recommendations are: