abstract class FormBase in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Form/FormBase.php \Drupal\Core\Form\FormBase
Provides a base class for forms.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
Expanded class hierarchy of FormBase
Related topics
121 files declare their use of FormBase
- ActionAdminManageForm.php in core/
modules/ action/ src/ Form/ ActionAdminManageForm.php - Contains \Drupal\action\Form\ActionAdminManageForm.
- AjaxFormsTestCommandsForm.php in core/
modules/ system/ tests/ modules/ ajax_forms_test/ src/ Form/ AjaxFormsTestCommandsForm.php - Contains \Drupal\ajax_forms_test\Form\AjaxFormsTestCommandsForm.
- AjaxFormsTestLazyLoadForm.php in core/
modules/ system/ tests/ modules/ ajax_forms_test/ src/ Form/ AjaxFormsTestLazyLoadForm.php - Contains \Drupal\ajax_forms_test\Form\AjaxFormsTestLazyLoadForm.
- AjaxFormsTestSimpleForm.php in core/
modules/ system/ tests/ modules/ ajax_forms_test/ src/ Form/ AjaxFormsTestSimpleForm.php - Contains \Drupal\ajax_forms_test\Form\AjaxFormsTestSimpleForm.
- AjaxFormsTestValidationForm.php in core/
modules/ system/ tests/ modules/ ajax_forms_test/ src/ Form/ AjaxFormsTestValidationForm.php - Contains \Drupal\ajax_forms_test\Form\AjaxFormsTestValidationForm.
File
- core/
lib/ Drupal/ Core/ Form/ FormBase.php, line 25 - Contains \Drupal\Core\Form\FormBase.
Namespace
Drupal\Core\FormView source
abstract class FormBase implements FormInterface, ContainerInjectionInterface {
use DependencySerializationTrait;
use LinkGeneratorTrait;
use RedirectDestinationTrait;
use StringTranslationTrait;
use UrlGeneratorTrait;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The config factory.
*
* Subclasses should use the self::config() method, which may be overridden to
* address specific needs when loading config, rather than this property
* directly. See \Drupal\Core\Form\ConfigFormBase::config() for an example of
* this.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static();
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// Validation is optional.
}
/**
* Retrieves a configuration object.
*
* This is the main entry point to the configuration API. Calling
* @code $this->config('book.admin') @endcode will return a configuration
* object in which the book module can store its administrative settings.
*
* @param string $name
* The name of the configuration object to retrieve. The name corresponds to
* a configuration file. For @code \Drupal::config('book.admin') @endcode,
* the config object returned will contain the contents of book.admin
* configuration file.
*
* @return \Drupal\Core\Config\ImmutableConfig
* A configuration object.
*/
protected function config($name) {
return $this
->configFactory()
->get($name);
}
/**
* Gets the config factory for this form.
*
* When accessing configuration values, use $this->config(). Only use this
* when the config factory needs to be manipulated directly.
*
* @return \Drupal\Core\Config\ConfigFactoryInterface
*/
protected function configFactory() {
if (!$this->configFactory) {
$this->configFactory = $this
->container()
->get('config.factory');
}
return $this->configFactory;
}
/**
* Sets the config factory for this form.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*
* @return $this
*/
public function setConfigFactory(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
return $this;
}
/**
* Resets the configuration factory.
*/
public function resetConfigFactory() {
$this->configFactory = NULL;
}
/**
* Gets the request object.
*
* @return \Symfony\Component\HttpFoundation\Request $request
* The request object.
*/
protected function getRequest() {
if (!$this->requestStack) {
$this->requestStack = \Drupal::service('request_stack');
}
return $this->requestStack
->getCurrentRequest();
}
/**
* Gets the route match.
*
* @return \Drupal\Core\Routing\RouteMatchInterface
*/
protected function getRouteMatch() {
if (!$this->routeMatch) {
$this->routeMatch = \Drupal::routeMatch();
}
return $this->routeMatch;
}
/**
* Sets the request stack object to use.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack object.
*
* @return $this
*/
public function setRequestStack(RequestStack $request_stack) {
$this->requestStack = $request_stack;
return $this;
}
/**
* Gets the current user.
*
* @return \Drupal\Core\Session\AccountInterface
* The current user.
*/
protected function currentUser() {
return \Drupal::currentUser();
}
/**
* Returns the service container.
*
* This method is marked private to prevent sub-classes from retrieving
* services from the container through it. Instead,
* \Drupal\Core\DependencyInjection\ContainerInjectionInterface should be used
* for injecting services.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container.
*/
private function container() {
return \Drupal::getContainer();
}
/**
* Gets the logger for a specific channel.
*
* @param string $channel
* The name of the channel.
*
* @return \Psr\Log\LoggerInterface
* The logger for this channel.
*/
protected function logger($channel) {
if (!$this->loggerFactory) {
$this->loggerFactory = $this
->container()
->get('logger.factory');
}
return $this->loggerFactory
->get($channel);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The logger factory. | |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
84 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
64 |
FormInterface:: |
public | function | Form constructor. | 157 |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 212 |
FormInterface:: |
public | function | Form submission handler. | 167 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Returns a redirect response object for the specified route. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |