I have created a custom block like this example:

https://www.drupal.org/docs/8/creating-custom-modules/create-a-custom-block

The block works but without contextual links. Why doesn't have the "configure block" contextual link? Where I have to define the contextual links that appear in all other blocks?

Comments

oriol_e9g created an issue. See original summary.

oriol_e9g’s picture

Title: Programatically blocks lost conetxtual links » Programatically blocks lost contextual links
oriol_e9g’s picture

Issue summary: View changes
cilefen’s picture

Title: Programatically blocks lost contextual links » Why doesn't a block I created programmatically display contextual links?
mnsh1416’s picture

Contextual link built for a custom block with latest drupal version (8.2.5).
Can you specify your version?

oriol_e9g’s picture

Yes, l'm using last stable version: 8.2.5.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

oriol_e9g’s picture

Status: Active » Fixed

My solution has been:

  1. Use a TWIG template for the output
  2. Add a div wrapper to the output with block attributes/classes
  3. Append {{ title_prefix }} and {{ title_sufix }} vars in the TWIG

If you simply output programmatically HTML, like documentation example, contextual links doesn't appear. If you use a TWIG templating like this works:

<div{{ attributes.addClass('block') }}>
  {{ title_prefix }}
  {{ title_suffix }}

  // Your custom output.

</div>

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.