Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I want to place the form to create a new message before the private messages inbox instead of redirecting the user to a new page.
I created a new Block Plugin using the code below:
<?php
namespace Drupal\sandbox_core\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a block with a the Create Private Message form.
*
* @Block(
* id = "create_private_message_form_block",
* admin_label = @Translation("Create Private Message Form block"),
* )
*/
class CreatePrivateMessageFormBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$private_message = \Drupal::entityTypeManager()->getStorage('private_message')->create();
return \Drupal::service('entity.form_builder')->getForm($private_message, 'add');
}
}
I placed the block into the Content region via Block Layout interface.
However, the "To" field does not render the same style as when the form is rendered on a separate page.
How can I achieve the same behavior for the "To" field?
Comment | File | Size | Author |
---|---|---|---|
CreatePrivateMessageFormBlock.png | 122.48 KB | carolpettirossi | |
CreatePrivateMessagePage.png | 42.48 KB | carolpettirossi |
Comments