RedirectFormBlock.php
Same filename in other branches
Namespace
Drupal\form_test\Plugin\BlockFile
-
core/
modules/ system/ tests/ modules/ form_test/ src/ Plugin/ Block/ RedirectFormBlock.php
View source
<?php
namespace Drupal\form_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a block containing a simple redirect form.
*
* @see \Drupal\form_test\Form\RedirectBlockForm
*
* @Block(
* id = "redirect_form_block",
* admin_label = @Translation("Redirecting form"),
* category = @Translation("Forms")
* )
*/
class RedirectFormBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* Constructs a new RedirectFormBlock.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $form_builder) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->formBuilder = $form_builder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('form_builder'));
}
/**
* {@inheritdoc}
*/
public function build() {
return $this->formBuilder
->getForm('Drupal\\form_test\\Form\\RedirectBlockForm');
}
/**
* {@inheritdoc}
*
* @todo Make cacheable once https://www.drupal.org/node/2351015 lands.
*/
public function getCacheMaxAge() {
return 0;
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
RedirectFormBlock | Provides a block containing a simple redirect form. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.