<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by P M Vijayalakshmi on Medium]]></title>
        <description><![CDATA[Stories by P M Vijayalakshmi on Medium]]></description>
        <link>https://medium.com/@lakshmi_86360?source=rss-45d2f60f450d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TOFmwAjG1D7xuXD9eBEfKA.jpeg</url>
            <title>Stories by P M Vijayalakshmi on Medium</title>
            <link>https://medium.com/@lakshmi_86360?source=rss-45d2f60f450d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 00:39:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lakshmi_86360/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Create Configurable Block programmatically In Drupal 8]]></title>
            <link>https://medium.com/valuebound/how-to-create-configurable-block-programmatically-in-drupal-8-32d036b1c709?source=rss-45d2f60f450d------2</link>
            <guid isPermaLink="false">https://medium.com/p/32d036b1c709</guid>
            <category><![CDATA[custom-block]]></category>
            <category><![CDATA[drupal-8]]></category>
            <category><![CDATA[configurable-block]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[drupal]]></category>
            <dc:creator><![CDATA[P M Vijayalakshmi]]></dc:creator>
            <pubDate>Wed, 12 Apr 2017 15:01:05 GMT</pubDate>
            <atom:updated>2017-04-13T06:54:56.324Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jCNp4hKwEM0BfcqFbNZVRg.jpeg" /><figcaption>Create configurable block in Drupal8</figcaption></figure><p>Blocks are the boxes of content that can be displayed in regions like sidebar first, sidebar second, content. This functionality is provided by the Block module in drupal 8. Here describing to creating Configurable Block programmatically in drupal 8 by using the drupal console.</p><p>Configurable Block module &amp; skeleton files created by following drupal console commands:</p><p><strong>$drupal generate: module</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*aYN4jnNMAIXlSKrm.png" /></figure><p>By using drupal console to generate configurable block module it create configure_block.info.yml file like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/0*axdAOsc8msfOcGXl.png" /></figure><p><strong>Configure_block.info.yml </strong>file contain the following information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/0*xqSKZcMdDZUNna-I.png" /></figure><p>The .info.yml file contains metadata about the project like the name of the project (configure_block), type (module), description (This is an example of configurable block programmatically in drupal 8), core (8.x), packages (Custom) and dependencies etc.</p><p>Next, we need to create a plugin for Block Module. Create folder Plugin under src, create Block folder under Plugin then create DefaultBlock.php file under Block folder.</p><ul><li>The path should be /src/Plugin/Block/DefaultBlock.php</li></ul><p>(or)</p><p>Next, we need to generate Block module using following drupal console command,</p><p><strong>$drupal generate:plugin:block</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*83JV3mhUzwb_MRtJ.png" /></figure><p>After generated configurable block module by using drupal console, it should be like,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/0*tW1bd4y2EVNz5ri1.png" /></figure><p>The Configurable block module Skeleton in drupal 8 is like this:</p><ul><li>module/custom/configure_block/src/Plugin/Block/DefaultBlock.php</li><li>module/custom/configure_block/configure_block.info.yml</li></ul><p>where configure_block is a module name for our custom configurable block. The plugin of configurable block module file will have following code where we are defining our configurable fields in drupal 8.</p><p><strong>DefaultBlock.php:</strong></p><pre>&lt;?php<br>namespace Drupal\Defaultblock\Plugin\Block;<br>use Drupal\Core\Block\BlockBase;<br>use Drupal\Core\Form\FormStateInterface;<br>use Drupal\Core\Block\BlockPluginInterface;<br>/** <br> * Provides a ‘CustomBlock’ block. <br> * <br> * @Block( * id = “id_custom_block”, <br> * admin_label = @Translation(“labelcustomblock”), <br> * ) <br> */<br>class DefaultBlock extends BlockBase implements BlockPluginInterface { <br>/** <br> * {@inheritdoc} <br> */ <br>public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); <br>$config = $this-&gt;getConfiguration(); </pre><pre>$form[‘hello_block_name’] = array ( ‘#type’ =&gt; ‘textfield’, ‘#title’ =&gt; $this-&gt;t(‘Who’), ‘#description’ =&gt; $this-&gt;t(‘Who do you want to say hello to?’), ‘#default_value’ =&gt; isset($config[‘name’]) ? $config[‘name’] : ‘’, ); </pre><pre>$form[‘mobile_number’] = array ( ‘#type’ =&gt; ‘textfield’, ‘#title’ =&gt; $this-&gt;t(‘your number’), ‘#description’ =&gt; $this-&gt;t(‘enter your personal mobile number’), ‘#default_value’ =&gt; isset($config[‘number’]) ? $config[‘number’] : ‘’, ); </pre><pre>$form[‘address’] = array ( ‘#type’ =&gt; ‘textfield’, ‘#title’ =&gt; $this-&gt;t(‘your address’), ‘#description’ =&gt; $this-&gt;t(‘enter your home town’), ‘#default_value’ =&gt; isset($config[‘town’]) ? $config[‘town’] : ‘’, );</pre><pre> return $form; <br>} <br>/** <br> * {@inheritdoc} <br> */ <br>public function blockSubmit($form, FormStateInterface $form_state) { $this-&gt;setConfigurationValue(‘name’, $form_state-&gt;getValue(‘hello_block_name’)); <br>$this-&gt;setConfigurationValue(‘number’, $form_state-&gt;getValue(‘mobile_number’)); <br>$this-&gt;setConfigurationValue(‘town’, $form_state-&gt;getValue(‘address’)); <br>} <br>public function build() { $<br>config = $this-&gt;getConfiguration(); <br>if (!empty($config[‘name’])) { <br>$name = $config[‘name’]; <br>} <br>else { <br>$name = $this-&gt;t(‘to no one’); <br>} <br>if (!empty($config[‘number’])) { <br>$number = $config[‘number’]; <br>} <br>else { <br>$number = $this-&gt;t(‘mobile number’); <br>} <br>if (!empty($config[‘town’])) { <br>$town = $config[‘town’]; <br>} <br>else { <br>$town = $this-&gt;t(“@town”); <br>} <br>return array( ‘#markup’ =&gt; $this-&gt;t(‘Hi my number is @number!,@name and my address @town’, array ( ‘@number’ =&gt; $number, ‘@name’ =&gt; $name, ‘@town’ =&gt; $town, ) ), ); <br>}<br>}</pre><p><a href="https://gist.github.com/munavlakshmi/9d50c1f27b80807865fd0dad14e47561/raw/ce205e3389fe4172815dc6c0fd898beddf878c03/DefaultBlock.php:">view raw</a><a href="https://gist.github.com/munavlakshmi/9d50c1f27b80807865fd0dad14e47561#file-defaultblock-php">DefaultBlock.php:</a> hosted with ❤ by <a href="https://github.com/">GitHub</a></p><p>Here we take three fields of the configurable block which are hello_block_name, mobile_number and address. The message is to be displayed, based on what you enter in those fields of block module in drupal 8.</p><p>Next, install your configurable block module in drupal 8.</p><p>Goto</p><p>Extend &gt;select install module&gt;select your module name&gt;click install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/0*965JWAyoG-C3pkkC.png" /></figure><p>Next place the configurable Block module in any regions are presented in drupal 8.</p><p>Goto</p><p>Structure&gt;Block Layout&gt;click place block icon&gt;select your block name&gt;select region&gt;save block.</p><p>Goto</p><p>Configuration block&gt;enter in the following field what you need to display output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/0*arYGsc4BZQHrPSTG.PNG" /></figure><p>Then go to the main page,</p><p>Configurable block Module displayed in some region (selected region example: sidebar second). It shows following output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*OGd16VqlNjEoDIVR.png" /></figure><p>I hope this was helpful in getting you started with Custom configurable block in Drupal 8.</p><p>Reference: <br><a href="https://github.com/munavlakshmi/create-configure-block-in-drupal-8">https://github.com/munavlakshmi/create-configure-block-in-drupal-8</a><br><a href="http://valuebound.com/resources/blog/how-to-create-configurable-block-programmatically-drupal-8">How to Create Configurable Block programmatically In Drupal 8</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32d036b1c709" width="1" height="1" alt=""><hr><p><a href="https://medium.com/valuebound/how-to-create-configurable-block-programmatically-in-drupal-8-32d036b1c709">How to Create Configurable Block programmatically In Drupal 8</a> was originally published in <a href="https://medium.com/valuebound">Valuebound</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>