ContentEntityConfirmFormBase
abstract class ContentEntityConfirmFormBase extends ContentEntityForm implements ConfirmFormInterface (View source)
Provides a generic base class for an entity-based confirmation form.
Traits
Provides dependency injection friendly methods for serialization.
Wrapper methods for the logger factory service.
Provides a trait for the messenger service.
Wrapper methods for the Redirect Destination.
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Properties
| protected array | $_serviceIds | An array of service IDs keyed by property name used for serialization. |
from DependencySerializationTrait |
| protected array | $_entityStorages | An array of entity type IDs keyed by the property name of their storages. |
from DependencySerializationTrait |
| protected LoggerChannelFactoryInterface | $loggerFactory | The logger channel factory service. |
from LoggerChannelTrait |
| protected MessengerInterface | $messenger | The messenger. |
from MessengerTrait |
| protected RedirectDestinationInterface | $redirectDestination | The redirect destination service. |
from RedirectDestinationTrait |
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected RequestStack | $requestStack | The request stack. |
from FormBase |
| protected ConfigFactoryInterface | $configFactory | The config factory. |
from FormBase |
| protected RouteMatchInterface | $routeMatch | The route match. |
from FormBase |
| protected string | $operation | The name of the current operation. |
from EntityForm |
| protected ModuleHandlerInterface | $moduleHandler | The module handler service. |
from EntityForm |
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
from EntityForm |
| protected ContentEntityInterface|RevisionLogInterface | $entity | The entity being used by this form. |
from ContentEntityForm |
| protected EntityTypeBundleInfoInterface | $entityTypeBundleInfo | The entity type bundle info service. |
from ContentEntityForm |
| protected TimeInterface | $time | The time service. |
from ContentEntityForm |
| protected EntityRepositoryInterface | $entityRepository | The entity repository service. |
from ContentEntityForm |
Methods
Gets the logger for a specific channel.
Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
Returns the redirect destination service.
Sets the redirect destination service.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Instantiates a new instance of this class.
Sets the request stack object to use.
Returns a redirect response object for the specified route.
Returns a string identifying the base form.
Initializes the form state and the entity before the first form build.
Process callback: assigns weights and hides extra fields.
Form element #after_build callback: Updates the entity with submitted data.
Returns the action form element for the current entity form.
Returns an array of supported actions for the current entity form.
Builds an updated entity object based upon the submitted form values.
Copies top-level form values to entity properties.
Determines which entity will be used by this form from a RouteMatch object.
Invokes the specified prepare hook variant.
Sets the entity type manager for this form.
Constructs a ContentEntityForm object.
Returns the bundle entity of the entity, or NULL if there is none.
Gets the names of all fields edited in the form.
Flags violations for the current form.
Checks whether the current form language matches the entity one.
Sets the form display.
Updates the form language to reflect any change to the entity language.
Add revision form fields if the entity enabled the UI.
Checks whether the revision form fields should be added to the form.
Returns additional text to display as a description.
Returns a caption for the button that confirms the action.
Returns a caption for the link which cancels the action.
Returns the internal name used to refer to the confirmation item.
Details
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
protected LoggerInterface
getLogger(string $channel)
Gets the logger for a specific channel.
$this
setLoggerFactory(LoggerChannelFactoryInterface $logger_factory)
Injects the logger channel factory.
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets the messenger.
protected array
getDestinationArray()
Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
protected RedirectDestinationInterface
getRedirectDestination()
Returns the redirect destination service.
$this
setRedirectDestination(RedirectDestinationInterface $redirect_destination)
Sets the redirect destination service.
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
static
create(ContainerInterface $container)
Instantiates a new instance of this class.
This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.
validateForm(array $form, FormStateInterface $form_state)
Form validation handler.
protected ImmutableConfig
config(string $name)
Retrieves a configuration object.
This is the main entry point to the configuration API. Calling
protected ConfigFactoryInterface
configFactory()
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.
$this
setConfigFactory(ConfigFactoryInterface $config_factory)
Sets the config factory for this form.
resetConfigFactory()
Resets the configuration factory.
protected Request
getRequest()
Gets the request object.
protected RouteMatchInterface
getRouteMatch()
Gets the route match.
$this
setRequestStack(RequestStack $request_stack)
Sets the request stack object to use.
protected AccountInterface
currentUser()
Gets the current user.
protected RedirectResponse
redirect(string $route_name, array $route_parameters = [], array $options = [], int $status = 302)
Returns a redirect response object for the specified route.
protected LoggerInterface
logger(string $channel)
Gets the logger for a specific channel.
This method exists for backward-compatibility between FormBase and LoggerChannelTrait. Use LoggerChannelTrait::getLogger() instead.
$this
setOperation(string $operation)
Sets the operation for this form.
string|null
getBaseFormId()
Returns a string identifying the base form.
string
getFormId()
Returns a unique string identifying the form.
The returned ID should be a unique string that can be a valid PHP function name, since it's used in hook implementation names such as hook_form_FORM_ID_alter().
array
buildForm(array $form, FormStateInterface $form_state)
Form constructor.
protected
init(FormStateInterface $form_state)
Initializes the form state and the entity before the first form build.
form(array $form, FormStateInterface $form_state)
Gets the actual form array to be built.
processForm($element, FormStateInterface $form_state, $form)
Process callback: assigns weights and hides extra fields.
afterBuild(array $element, FormStateInterface $form_state)
Form element #after_build callback: Updates the entity with submitted data.
Updates the internal $this->entity object with submitted values when the form is being rebuilt (e.g. submitted via AJAX), so that subsequent processing (e.g. AJAX callbacks) can rely on it.
protected
actionsElement(array $form, FormStateInterface $form_state)
Returns the action form element for the current entity form.
protected array
actions(array $form, FormStateInterface $form_state)
Returns an array of supported actions for the current entity form.
This function generates a list of Form API elements which represent actions supported by the current entity form.
submitForm(array $form, FormStateInterface $form_state)
Form submission handler.
int
save(array $form, FormStateInterface $form_state)
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
EntityInterface
buildEntity(array $form, FormStateInterface $form_state)
Builds an updated entity object based upon the submitted form values.
For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.
protected
copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state)
Copies top-level form values to entity properties.
This should not change existing entity properties that are not being edited by this form.
EntityInterface
getEntity()
Gets the form entity.
The form entity which has been used for populating form element defaults.
$this
setEntity(EntityInterface $entity)
Sets the form entity.
Sets the form entity which will be used for populating form element defaults. Usually, the form entity gets updated by \Drupal\Core\Entity\EntityFormInterface::submit(), however this may be used to completely exchange the form entity, e.g. when preparing the rebuild of a multi-step form.
EntityInterface
getEntityFromRouteMatch(RouteMatchInterface $route_match, string $entity_type_id)
Determines which entity will be used by this form from a RouteMatch object.
protected
prepareEntity()
Prepares the entity object before the form is built first.
protected
prepareInvokeAll(string $hook, FormStateInterface $form_state)
Invokes the specified prepare hook variant.
string
getOperation()
Gets the operation identifying the form.
$this
setModuleHandler(ModuleHandlerInterface $module_handler)
Sets the module handler for this form.
$this
setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager)
Sets the entity type manager for this form.
__construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time)
Constructs a ContentEntityForm object.
protected EntityInterface|null
getBundleEntity()
Returns the bundle entity of the entity, or NULL if there is none.
protected string[]
getEditedFieldNames(FormStateInterface $form_state)
Gets the names of all fields edited in the form.
If the entity form customly adds some fields to the form (i.e. without using the form display), it needs to add its fields here and override flagViolations() for displaying the violations.
protected
flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
Flags violations for the current form.
If the entity form customly adds some fields to the form (i.e. without using the form display), it needs to add its fields to array returned by getEditedFieldNames() and overwrite this method in order to show any violations for those fields; e.g.:
protected
initFormLangcodes(FormStateInterface $form_state)
Initializes form language code values.
string
getFormLangcode(FormStateInterface $form_state)
Gets the code identifying the active form language.
bool
isDefaultFormLangcode(FormStateInterface $form_state)
Checks whether the current form language matches the entity one.
EntityFormDisplayInterface
getFormDisplay(FormStateInterface $form_state)
Gets the form display.
$this
setFormDisplay(EntityFormDisplayInterface $form_display, FormStateInterface $form_state)
Sets the form display.
Sets the form display which will be used for populating form element defaults.
updateFormLangcode(string $entity_type_id, EntityInterface $entity, array $form, FormStateInterface $form_state)
Updates the form language to reflect any change to the entity language.
There are use cases for modules to act both before and after form language being updated, thus the update is performed through an entity builder callback, which allows to support both cases.
updateChangedTime(EntityInterface $entity)
Updates the changed time of the entity.
Applies only if the entity implements the EntityChangedInterface.
protected
addRevisionableFormFields(array $form)
Add revision form fields if the entity enabled the UI.
protected bool
getNewRevisionDefault()
Should new revisions created on default.
protected bool
showRevisionUi()
Checks whether the revision form fields should be added to the form.
TranslatableMarkup
getDescription()
Returns additional text to display as a description.
TranslatableMarkup
getConfirmText()
Returns a caption for the button that confirms the action.
TranslatableMarkup
getCancelText()
Returns a caption for the link which cancels the action.
string
getFormName()
Returns the internal name used to refer to the confirmation item.
delete(array $form, FormStateInterface $form_state)
{@inheritdoc}
The delete() method is not used in ContentEntityConfirmFormBase. This overrides the default implementation that redirects to the delete-form confirmation form.
Confirmation forms should override submitForm() instead for their logic.