How to display custom token in custom block In a Drupal 8 website I created a custom token that is working in basic page.

Then I created a custom block with a WYSIWYG field :

class Myblock extends BlockBase {

  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }

  public function getMachineName() {
    return 'my_custom_blcok';
  }


  public function label() {
    return $this-&gt;t('Block label');
  }

  public function blockForm($form, FormStateInterface $form_state) {
    $form = parent::blockForm($form, $form_state);
    $config = $this-&gt;getConfiguration();

    $form['my_field'] = [
      '#type' =&gt; 'text_format',
      '#format' =&gt; 'content_manager',
      '#title' =&gt; $this-&gt;t('Field name'),
      '#default_value' =&gt; isset($config['my_field']['value']) ? $config['my_field']['value'] : '',
    ];

    return $form;
  }

  public function blockSubmit($form, FormStateInterface $form_state) {
    $this-&gt;setConfigurationValue('my_field', $form_state-&gt;getValue('my_field'));
  }


  public function build() {
    $config = $this-&gt;getConfiguration();
    $content = $config['my_field']['value'];

    return [
        '#theme' =&gt; 'simulator_block',
        '#content' =&gt; $content,
      ];
  }
}


If I type My content [module:my_token] in the WYSIWYG.

The following content is display :

&lt;p&gt;My content [module:my_token]&lt;/p&gt;


How can I replace the token ?
Place the formatted text in a render element processed_text:

 $content = [
    '#type' =&gt; 'processed_text',
    '#text' =&gt; $config['my_field']['value'],
    '#format' =&gt; 'content_manager',
  ];

  return [
    '#theme' =&gt; 'simulator_block',
    '#content' =&gt; $content,
  ];


Configure the text format to include the token filter.